0

I am trying to use

del df['CustomerAge']
del df['ID']

using a Jupyter notebook on a Windows 10 PC running 1803, installed via Anaconda and fully updated. The first row runs just fine while the second one won't run. But on two friends of mine it works, they are using a Mac though... I am calling del df['ID'] multiple times in the code, it never works - as if it would have a problem with the name "ID".

How can I solve this? (Without buying a Mac...)

ReRed
  • 343
  • 4
  • 15

1 Answers1

1

I would always just use the following syntax to delete a column in Pandas:

df.drop('ID', axis=1, inplace=True)

There is some information in this thread which discusses why using del is not good practice.

Note that this method also has the benefit of being able to delete multiple columns at once:

df.drop(['ID', 'CustomerAge'], axis=1, inplace=True)

See documentation on drop.

sjw
  • 6,213
  • 2
  • 24
  • 39