Series的基本操作

Python笔记本
475 0

代码

from pandas import Series
import pandas as pd
#手动设置索引
obj1 = Series ( [4, 7, 5, -3], index = ['a', 'b', 'c', 'd'])
print( obj1 )
obj1 ['a'] = 8
print( obj1 )
#判断是否在Series里
print ( 'a' in obj1 )
print ( 'f' in obj1 )

#字典转换成Series
sdata = {'Beijin':11000, 'Shanghai': 20000, 'Shenzhen': 12222 }
obj2 = Series( sdata )
print( obj2 )
#修改索引
obj2.index = {'bj', 'sh', 'sz'}
print( obj2 )

运行

最后更新 2019-10-08
评论 ( 0 )
评论已关闭