Home > database >  Retain pandas dataframe where column names not in another dataframe
Retain pandas dataframe where column names not in another dataframe

Time:01-20

I want to create a new dataframe to store columns of all_kirpII_rna dataframe where the column names are NOT in the mrna_cimp dataframe.

mrna_NONCIMP_df = all_kirpII_rna[all_kirpII_rna.columns.isin(mrna_cimp.columns) == "False"]

Traceback:

KeyError: False

CodePudding user response:

"False" is a string, not a boolean. And if you have a list of booleans you can mask with them directly

You want something like

mrna_NONCIMP_df = all_kirpII_rna.loc[:,~all_kirpII_rna.columns.isin(mrna_cimp.columns)]

  • Related