pandas入门核心基础结构
演示:jupyter
Series
Series是一维标记的数组,能够保存任何数据类型(整数,字符串,浮点数,Python对象等),轴标签统称为index。创建系列的基本方法是调用:
s = pd.Series(data, index=index)
其中index是一个列表,用来作为数据的标签。data 可以是不同的数据类型:
●Python字典
●ndarray对象
●一个标量值
s=pd.Series(np.random.randn(5))
s
run结果:
0 1.372634
1 0.862209
2 1.588282
3 0.818007
4 0.019875
dtype: float64
字典里的键变成标签,值为值
d={
'a':0,'b':1,'d':3}
s=pd.Series(d,index=list('abcd'))
s
Out[10]:
a 0.0
b 1.0
c NaN
d 3.0
dtype: float64
Series特性
Series对象的性质
●类ndarray对象
●类dict对象
●标签对齐操作
1 类ndarray对象
和ndarray一样可以索引,求值等
如:
in
s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd',