3 回答
TA贡献1818条经验 获得超8个赞
__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贡献1993条经验 获得超5个赞
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
添加回答
举报