如果索引为数学,我试图将一个数据帧除以另一个。我有2个数据框,其中包含2017年至2020年的国家人口,另一个是这些国家的二氧化碳排放量。我唯一的问题是,我的第二个数据框具有比第一个数据框更多的国家/地区,并且顺序不完全相同。这是情况的一瞥。
df1 df2
country 2017 2018 2019 2020 country 2017 2018 2019 2020
country1 120 140 200 440 country2 200 200 400 500
country2 100 200 120 250 country3 300 360 600 720
country5 25 25 50 35 country5 100 50 250 350
我尝试了 df1.div(df2),但是结果到处都是NAN。如果df1中的国家/地区也位于df2中,那么我最终想做的就是将df1除以df2。就像我的问题一样,我只是对country2有一个结果。 这是一个示例结果:
df
country 2017 2018 2019 2020
country1 NAN NAN NAN NAN
country2 2 1 3.3 2
Country5 4 2 5 10