Skip to content
Advertisement

Compare two dataframes with same index using one column

I have the following two dataframes (samples). I’d like to know which companies had their sales changed between the two dataframes. For example, AAPL is different in the second dataframe.

        Sales  52W High  52W Low
Root
A       4.81B   -0.1072   0.1082
AA     12.81B   -0.3124   0.0709
AABA  266.05M   -0.2038   0.0437
AAL    43.52B   -0.3285   0.1131
AAN     3.61B   -0.0208   0.4716
AAOI  321.80M   -0.5196   0.5195
AAP     9.42B   -0.0153   1.1190
AAPL  255.27B   -0.0101   0.5210
AAXN  385.40M   -0.1005   2.3432
ABB    35.52B   -0.1870   0.0987
        Sales  52W High  52W Low
Root
A       4.81B   -0.1019   0.1149
AA     12.81B   -0.3527   0.0082
AABA  266.05M   -0.2212   0.0208
AAL    43.52B   -0.3487   0.0797
AAN     3.61B   -0.0196   0.4733
AAOI  321.80M   -0.5478   0.4303
AAP     9.42B   -0.0216   1.1218
AAPL  243.89B   -0.0286   0.4957
AAXN  385.40M   -0.0806   2.4171
ABB    35.52B   -0.1838   0.1030

Advertisement

Answer

This you can using ne (not equal)

df1.Sales.ne(df2.Sales)# the one mask as True is the different 
Out[482]: 
Root
A       False
AA      False
AABA    False
AAL     False
AAN     False
AAOI    False
AAP     False
AAPL     True
AAXN    False
ABB     False
Name: Sales, dtype: bool
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement