pandas有三种数据结构形式,分别是Series,DataFrame和索引对象。
1.Series
Series和一维数组很像,只是它的每一个值都有一个索引,输出显示时索引在左,值在右。
如果语言无法清晰表达,不妨看段代码,毕竟talk is cheap,show me your code!!!
首先导入pandas库:
>>from pandas import Series
用数组生成一个Series:
>>test1=Series([1,2,3,4,5])
>>print test1
输出:
0 1
1 2
2 3
3 4
4 5
dtype: int64
上面的例子我们没有指定索引。没有索引的情况下索引值默认从1开始往后排。
接下来我们尝试用index参数指定索引:
>>test2=Series([2,3,3,3],index=['c','o','d','e'])
c 2
o 3
d 3
e 3
dtype: int64
也可以用字典生成Series:
>>> dic={'h':1,'e':2,'l':3}
>>> test3=Series(dic)
>>> print test3
e 2
h 1
l 3
dtype: int64
OK