python remove or delete last column of a dataframe

description: python remove last column

init data

1
2
3
4
5
6
7
8
9
10
11
12
import pandas 
data = pandas.DataFrame({
'a': [1, 2, 3],
'b': [0.1, 0.2, 0.3],
'c': ['a', 'b', 'a'],
'd': [1, 2, 3]
})
# data
# a b c d
# 0 1 0.1 a 1
# 1 2 0.2 b 2
# 2 3 0.3 a 3

drop last column

1
data[data.columns[:-1]]

output

1
2
3
4
   a    b  c
0 1 0.1 a
1 2 0.2 b
2 3 0.3 a