3 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
__getitem__
df1 = df[['a','b']]
df1 = df.iloc[:,0:2] # Remember that Python does not slice inclusive of the ending index.
copy()
df1 = df.iloc[0,0:2].copy() # To avoid the case where changing df1 also changes df
iloc
iloc
get_loc
columns
{df.columns.get_loc(c):c for idx, c in enumerate(df.columns)}
iloc
.

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
df.columns
['index','a','b','c']
newdf = df[df.columns[2:4]] # Remember, Python is 0-offset! The "3rd" entry is at slot 2.
df.ix
.columns
'index'
DataFrame
df.index
Index
df['index']
df.index
Index
Series
df.columns
pd.Index
添加回答
舉報(bào)