Pandas - drop last column of DataFrame
Use drop with the columns index:
fish_frame = fish_frame.drop(fish_frame.columns[-1],axis=1)
Output:
0 1 2
0 #0721 NaN NaN
1 GBE COD 746 $2.00
2 GBW COD 13,894 $0.50
3 GOM COD 60 $2.00
4 GB WINTER FLOUNDER 94,158 $0.25
5 GOM WINTER FLOUNDER 3,030 $0.50
6 GBE HADDOCK 18,479 $0.02
7 GOM HADDOCK 0 $0.02
8 GBW HADDOCK 110,470 $0.02
9 HAKE 259 $1.30
10 PLAICE 3,738 $0.40
11 POLLOCK 3,265 $0.02
12 WITCH FLOUNDER 1,134 $1.30
13 SNE YT 1,458 $0.65
14 GB YT 4,499 $0.70
15 REDFISH 841 $0.02
16 54 DAS @ $8.00/DAY = 432.00 NaN NaN
Use iloc
and list indexing
fish_frame = fish_frame.iloc[:, :-1]
0 1 2
0 #0721 NaN NaN
1 GBE COD 746 $2.00
2 GBW COD 13,894 $0.50
3 GOM COD 60 $2.00
4 GB WINTER FLOUNDER 94,158 $0.25
5 GOM WINTER FLOUNDER 3,030 $0.50
6 GBE HADDOCK 18,479 $0.02
7 GOM HADDOCK 0 $0.02
8 GBW HADDOCK 110,470 $0.02
9 HAKE 259 $1.30
10 PLAICE 3,738 $0.40
11 POLLOCK 3,265 $0.02
12 WITCH FLOUNDER 1,134 $1.30
13 SNE YT 1,458 $0.65
14 GB YT 4,499 $0.70
15 REDFISH 841 $0.02
16 54 DAS @ $8.00/DAY = 432.00 NaN NaN
If you want to drop the last column
df = df.iloc[:,:-1]
if particular column needs to be dropped with index
df = df.drop(df.columns[column_index],axis=1)
with column name
df = df.drop(['column_name'],axis =1)