Pandas Select DataFrame columns using boolean

后端 未结 5 841
我在风中等你
我在风中等你 2020-12-30 23:05

I want to use a boolean to select the columns with more than 4000 entries from a dataframe comb which has over 1,000 columns. This expression gives me a Boolean

5条回答
  •  悲哀的现实
    2020-12-30 23:27

    What is returned is a Series with the column names as the index and the boolean values as the row values.

    I think actually you want:

    this should now work:

    comb[criteria.index[criteria]]
    

    Basically this uses the index values from criteria and the boolean values to mask them, this will return an array of column names, we can use this to select the columns of interest from the orig df.

提交回复
热议问题