import numpy as np
import pandas as pd
dates = pd.date_range('20170101',periods=6)
df1 = pd.DataFrame(np.arange(24).reshape((6,4)),
index=dates,columns=['A','B','C','D'])
df1
df1['A']
df1.A
df1[0:2]
df1['20170102':'20170104']
df1.loc['20170102']
df1.loc['20170102',['A','C']]
df1.loc[:,['A','B']]
df1.iloc[2]
df1.iloc[1:3,2:4]
df1.iloc[[1,2,4],[1,3]]
df1.iloc[:df1.index.get_loc('20170101')+2,2:4]
df1.A > 6
df1[df1.A>6]
pandas赋值
dates = np.arange(20170101,20170107)
df1 = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,
columns=['A','B','C','D'])
df1
df1.iloc[2,2]
df1.iloc[2,2] = 100
df1
df1.loc[20170102,'B'] = 200
df1
df1[df1.A>10] = 0
df1
df1.A[df1.A==0] = 1
df1
df1['E'] = 10
df1
df1['F'] = pd.Series([1,2,3,4,5,6],index=dates)
df1
df1.loc[20170107,['A','B','C']] = [1,2,3]
df1
s1 = pd.Series([1,2,3,4,5,6],index=['A','B','C','D','E','F'])
s1.name = 'S1'
df2 = df1.append(s1)
df2
df1.insert(1,'G',df2['E'])
df1
g = df1.pop('G')
df1.insert(6,'G',g)
df1
del df1['G']
df1
df2 = df1.drop(['A','B'],axis=1)
df2
df2 = df1.drop([20170101,20170102],axis=0)
df2