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