One - One Code All

Blog Content

python中pandas的series用法

Python 统计学-科学计算   2011-11-22 22:36:09

pandas的series类似于字典结构。


判断索引是否存在:

>>> from pandas import Series,DataFrame
>>> obj2 = Series([2,6,12,15,18,20],index=[0,1,2,3,4,5])
>>> print(obj2)
0     2
1     6
2    12
3    15
4    18
5    20
dtype: int64
>>> if 1 in obj2:
...     print(1)
...
1
>>> if 8 in obj2:
...     print(1)
...
>>> if 12 in obj2:
...     print(1)
...

>>> obj2.isin([2])
0     True
1    False
2    False
3    False
4    False
5    False
dtype: bool

其他用法:


1、append,合并
obj.append(obj2)

2、obj.diff(),每行与上一行的差值

3、obj3.unique() 计算唯一值

4、is_unique,判断是否有重复值,如果没有返回True,否则返回False

5、is_monotonic,当各元素均大于等于前值时,返回True,否则返回False

6、drop,删除

7、isin,判断是否包含在参数中

8、reindex,创建一个新的索引对象



上一篇:numpy正态分布normal与多元正态分布multivariate_normal
下一篇:python的numpy库中将矩阵转换为列表等函数

The minute you think of giving up, think of the reason why you held on so long.