python - Pandas extract columns from dataframe which are not present in another dataframe -
i have foll 2 dataframes:
df_a b c d 12 23 34 45 22 32 54 87
and,
df_b b c 23 34 32 54
how select columns in df_a not present in df_b, resulting in following dataframe (you can assume df_b subset of df_a):
a d 12 45 22 87
i tried this:
df_a[df_a.columns.values <> df_b.columns.values]
but results in keyerror
>>> df_a.columns.difference(df_b.columns) index(['a', 'd'], dtype='object')
will give columns, , can do:
>>> cols = df_a.columns.difference(df_b.columns) >>> df_a[cols] d 0 12 45 1 22 87
Comments
Post a Comment