5

How can I delete multiple columns in one pass? I know this works

del df['A']
del df['B']

but

del df[['A', 'B']]

doesn't.

highpost
  • 1,263
  • 2
  • 14
  • 25
  • using `drop` method? https://groups.google.com/forum/#!topic/pystatsmodels/LPcCJem5vDE – dm03514 Jul 24 '13 at 15:42
  • I'd just like to add that the del statement won't ever work to delete multiple values because the magic method __delitem__(self, key) only takes one argument. – Blaine Jul 24 '13 at 15:54
  • 5
    Possible duplicate of [Deleting multiple columns in Pandas](https://stackoverflow.com/q/28538536/1278112) – Shihe Zhang Nov 06 '17 at 05:39
  • 2
    You will notice that I asked this question in 2013, two years before the referenced question/answer occurred. Please find something better to do. – highpost Nov 06 '17 at 18:59

1 Answers1

13

You can use .drop:

df = df.drop(['A', 'B'], axis=1)
Jon Clements
  • 138,671
  • 33
  • 247
  • 280