我想选择除数据框的最后3列之外的所有列。
我试过了 :
df.loc[:,-3]
Run Code Online (Sandbox Code Playgroud)
但这不起作用
编辑:标题
使用这个df.columns被切片,并放入df[...]括号中:
print(df[df.columns[:-3]])
Run Code Online (Sandbox Code Playgroud)
选择除最后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
Run Code Online (Sandbox Code Playgroud)