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,创建一个新的索引对象