如何在Python中选择除最后3列之外的所有数据帧列
我想选择数据帧的最后3列以外的所有列 我试过:如何在Python中选择除最后3列之外的所有数据帧列,python,pandas,dataframe,Python,Pandas,Dataframe,我想选择数据帧的最后3列以外的所有列 我试过: df.loc[:,-3] 但它不起作用 编辑:title使用此df。将要切片的列放入df[…]括号中: print(df[df.columns[:-3]]) 选择除最后3列之外的所有内容,使用iloc执行此操作: In [1639]: df Out[1639]: a b c d e 0 1 3 2 2 2 1 2 4 1 1 1 In [1640]: df.iloc[:,:-3] Out[1640]:
df.loc[:,-3]
但它不起作用
编辑:title使用此
df。将要切片的列
放入df[…]
括号中:
print(df[df.columns[:-3]])
选择除最后3列之外的所有内容,使用iloc执行此操作:
In [1639]: df
Out[1639]:
a b c d e
0 1 3 2 2 2
1 2 4 1 1 1
In [1640]: df.iloc[:,:-3]
Out[1640]:
a b
0 1 3
1 2 4