How to select all but the 3 last columns of a dataframe in Python
Use this df.columns
being sliced, and putted into a df[...]
bracket:
print(df[df.columns[:-3]])
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