标签:数据 null false dex 获取 col panda class array
1、导入:import pandas as pd
2、Series 函数,默认标签0-(n-1)
In [3]: a=pd.Series([1,2,3,4]) In [4]: a Out[4]: 0 1 1 2 2 3 3 4 dtype: int64
获取值与标签:
In [5]: a.values Out[5]: array([1, 2, 3, 4], dtype=int64) In [6]: a.index Out[6]: RangeIndex(start=0, stop=4, step=1)
设定标签值:
In [7]: a=pd.Series([1,2,3,4],index=[‘a‘,‘b‘,‘c‘,‘d‘]) In [8]: a Out[8]: a 1 b 2 c 3 d 4 dtype: int64
可使用标签进行索引:
In [9]: a[‘b‘] Out[9]: 2
根据值范围取值:
In [10]: a[a>2] Out[10]: c 3 d 4 dtype: int64
计算:
In [11]: a*a Out[11]: a 1 b 4 c 9 d 16 dtype: int64
判断:
In [12]: ‘a‘ in a Out[12]: True In [13]: ‘b‘ not in a Out[13]: False
处理缺失数据:
In [18]: pd.isnull(a) Out[18]: a False b False c False d False dtype: bool
In [19]: pd.notnull(a) Out[19]: a True b True c True d True dtype: bool
给标签列,整个数组命名:
In [20]: a.name=‘text‘ In [21]: a.index.name=‘index‘ In [22]: a Out[22]: index a 1 b 2 c 3 d 4 Name: text, dtype: int64
标签:数据 null false dex 获取 col panda class array
原文地址:https://www.cnblogs.com/syl-777/p/12326042.html