标签:
1、Series
series是类似于一维数组的对象,它是由一组数据以及与之相关的数据标签(即索引)组成,仅由一组数据即可产生最简单的series:
p=pd.Series([1,2,4,3]) p Out[5]: 0 1 1 2 2 4 3 3 dtype: int64
p.values
Out[6]: array([1, 2, 4, 3], dtype=int64)
p.index
Out[7]: Int64Index([0, 1, 2, 3], dtype=‘int64‘)
索引(index)在左,值(value)在右
p.values Out[6]: array([1, 2, 4, 3], dtype=int64) p.index Out[7]: Int64Index([0, 1, 2, 3], dtype=‘int64‘)
可通过索引的方式来选取Series中的单个或一组值。
p[‘0’]
numpy数组之间的计算:(obj2)
obj2
Out[22]:
a 4
b 7
c -5
d 3
dtype: int64
obj2[obj2>0] Out[26]: a 4 b 7 d 3 dtype: int64 obj2 * 2 Out[27]: a 8 b 14 c -10 d 6 dtype: int64 import numpy as np np.exp(obj2) Out[29]: a 54.598150 b 1096.633158 c 0.006738 d 20.085537 dtype: float64
如果数据放在字典中,可以直接进行调用创建series
sdata = {‘Ohio‘:35000,‘Texas‘:71000,‘Oregon‘:16000,‘Utah‘:5000}
obj3 = pd.Series(sdata)
obj3
Out[34]:
Ohio 35000
Oregon 16000
Texas 71000
Utah 5000
dtype: int64
如
标签:
原文地址:http://www.cnblogs.com/groupe/p/4921490.html