I have two dataframes that look like this:
df_1 = pd.DataFrame({
'A' : [1.0, 2.0, 3.0, 4.0],
'B' : [100, 200, 300, 400],
'C' : [2, 3, 4, 5]
})
df_2 = pd.DataFrame({
'B' : [1.0, 2.0, 3.0, 4.0],
'C' : [100, 200, 300, 400],
'D' : [2, 3, 4, 5]
})
Now if I utilize pandas .isin function I can do something nifty like this
>>> print df_2.columns.isin(df_1.columns)
array([ True, True, False], dtype=bool)
Columns B
and C
from df_2
exist in df_1
while D
doesn't
My question is: does anyone know of a way to return the columns' labels for columns that exist in df_2 but not in df_1
something like this
array([u'D'], dtype=string)
Thank you in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…