Horacio Nesman
Horacio Nesman

Reputation: 111

df.drop is not working

I am very stuck with this, obviously I have little experience, so every opinion is welcome:

df = pd.concat((pd.read_csv(f,delimiter = '|') for f in onlyfiles)
# I have to delete the column 'Unnamed: 0'
df = df.drop(['Unnamed: 0'])
df.head()

If somebody can tell something about this 'Unnamed: 0' column, I don't understand what's the use of this?

Thanks!

Upvotes: 0

Views: 2610

Answers (2)

Allen Qin
Allen Qin

Reputation: 19947

If you want to drop the column inplace, there's another way to do it.

del(df['Unnamed: 0'])

Upvotes: 0

piRSquared
piRSquared

Reputation: 294258

DOCS

'Unnamed: 0' is a column name. You'll need to pass the axis=1 parameter to drop

df = df.drop(['Unnamed: 0'], axis=1)

Because the axis parameter is the second parameter, that can be shortened to

df = df.drop(['Unnamed: 0'], 1)

Upvotes: 4

Related Questions