Lucas Dresl
Lucas Dresl

Reputation: 1170

drop column and row index at the same time

I am looking to remove from the following df the first row and the first column.

                id                                             
bin_015          0         1         2        3       4       5
bin_01                                                         
0        5339604.0       NaN       NaN      NaN     NaN     NaN
1         377342.0  122580.0   85688.0   9501.0  1095.0   156.0
2              NaN  235426.0  313317.0  17025.0   456.0    33.0
3              NaN   16581.0   10759.0  40005.0  3422.0    84.0
4              NaN    1712.0     387.0   1851.0  8746.0   756.0
5              NaN     239.0      40.0     50.0   353.0  2197.0

the way i try was

df.drop(df.index[0])

which drop the row index = 0 but then when i try to remove the first column i throw me an error

my try for removing the first column, but without succeding

df.drop(df.index[0],axis==1)

Upvotes: 0

Views: 45

Answers (2)

Matti Lyra
Matti Lyra

Reputation: 13078

I think what you want is

df.iloc[1:, 1:]

Upvotes: 1

r.ook
r.ook

Reputation: 13848

Would this work?

df.drop(index=0, columns=0)

Combined your first try with this.

Upvotes: 0

Related Questions