如何在Python中选择除数据框的最后3列之外的所有列 [英] How to select all but the 3 last columns of a dataframe in Python
本文介绍了如何在Python中选择除数据框的最后3列之外的所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择除数据框最后3列之外的所有列.
I want to select all but the 3 last columns of my dataframe.
我尝试过:
df.loc[:,-3]
但这不起作用
标题
推荐答案
选择所有内容除了最后3列,请使用 iloc
:
Select everything EXCEPT the last 3 columns, do this using 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
这篇关于如何在Python中选择除数据框的最后3列之外的所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文