简体   繁体   English

使用一列比较具有相同索引的两个数据帧

[英]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.例如,AAPL 在第二个数据帧中是不同的。

        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

This you can using ne (not equal)这你可以使用ne (不等于)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM