How to select all columns, except one column in pandas?

后端 未结 9 1801
不思量自难忘°
不思量自难忘° 2020-11-29 14:51

I have a dataframe look like this:

import pandas
import numpy as np
df = DataFrame(np.random.rand(4,4), columns = list(\'abcd\'))
df
      a         b                


        
9条回答
  •  孤街浪徒
    2020-11-29 15:19

    I think a nice solution is with the function filter of pandas and regex (match everything except "b"):

    df.filter(regex="^(?!b$)")
    

提交回复
热议问题