Python将两个相同的数据框组成一个新的数据框

问题描述 投票:0回答:1

我有两个看起来相似的数据框:

df1:

enter image description here

df2:

enter image description here

我想通过乘以df2中的值(对于“国家/地区”-“城市”组合)来更新df1中的“长度”列:

enter image description here

[有一些Google,但只能找到类似,合并或合并的东西。就像在数据框之间相乘一样。

任何帮助将不胜感激。

python dataframe multiplying
1个回答
0
投票

您首先可以根据国家/地区和城市加入2 df,同时获得length1和length2

combineddf = pd.merge(df1,df2,on=['country','city'])

然后将两个长度列相乘。

© www.soinside.com 2019 - 2024. All rights reserved.