Retain pandas dataframe where column names not in another dataframe

Question:

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
Asked By: melolilili

||

Answers:

"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)]

Answered By: Mark_Anderson
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.