0

For example, now I have dataframe like this:

      A B C D E F G H 
row0  1 2 3 4 5 6 7 8

A,B,C..are column names.

Now I'd like to remove columns, whose names are included in a list:

listrem = ['A','C','E'] 

So basically I would like to see:

      B D F G H
row0  2 4 6 7 8 

How could I do that? Thanks!

LookIntoEast
  • 8,048
  • 18
  • 64
  • 92
  • Duplicate: http://stackoverflow.com/questions/14940743/selecting-excluding-sets-of-columns-in-pandas – sgrg Apr 19 '17 at 14:38

1 Answers1

2
>>> df[[i for i in df.columns if i not in listrem]]
      B  D  F  G  H
row0  2  4  6  7  8

If you do not car of the order of columns:

df[list(set(df.columns)-set(listrem))]
Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87