1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import pandas as pd import numpy as np d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])} df=pd.DataFrame(d) print df mean=df.mean() print mean
dates=pd.date_range('20161120',periods=6) print dates
df1=pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD')) print df1
df2=pd.DataFrame({'A':1.,'B':pd.Series(1,index=list(range(5)),dtype='float32'),'C':pd.Timestamp('20161124'),'D':np.array([3]*5,dtype='int32'),'E':pd.Categorical(['test','train','test','train','test']),'F':'foo'}) print df2
print df1.tail(1)
print df1.head(3)
print df2.index
print df2.columns
print df2.values
print df1.describe()
print df1.T
print df1.sort_index(axis=1,ascending=False)
print df1.sort(columns='B')
print 'df1[A]'+'\n',df1['A']
print 'df1[0:3]'+'\n',df1[0:2],'\n'
print df1.loc[dates[0]],'\n\n'
print df1.loc[dates[0:2],['C','A']]
dropna 根据各标签值中是否存在缺失数据对轴标签进行过滤,可通过阀值调节对缺失值的容忍度 fillna 用指定的或插值方法(如ffil或bfill)填充缺失数据 isnull 返回一个含有布尔值的对象,这些布尔值表示哪些值是缺失值/NA,该对象的类型与源类型一样 notnull isnull的否定式
|