subtracting two dataframes

前端 未结 2 948
你的背包
你的背包 2020-12-03 18:31

df1:

City, 2015-12-31, 2016-01-31, ...
YYZ  562.14, -701.18, ...
DFW  562.14, -701.18, ...
YYC  562.14, -701.18, ...

df2:



        
相关标签:
2条回答
  • 2020-12-03 19:06

    Does this work?

    df2.drop(['City']).subtract(df1.drop(['City']))
    
    0 讨论(0)
  • 2020-12-03 19:16

    Move the City column into the index. The DataFrames will align by both index and columns first and then do subtraction. Any combination not present will result in NaN.

    df2.set_index('City').subtract(df1.set_index('City'), fill_value=0)
    
    0 讨论(0)
提交回复
热议问题