添加来自不同数据帧的列中的值



所以我有这两个数据帧:

df1:
No_One
0  Team_1   1 
1  Team_2   1   
2  Team_3   1
df2:
No_Two
0  Team_1   2
1  Team_2   2
2  Team_3   2

当我尝试做:

df2['No_Two'] = df1['No_One'] + df2['No_Two']
print(df2)

我得到:

df2:
No_Two
0  Team_1   NaN
1  Team_2   NaN
2  Team_3   NaN

而不是

df2:
No_Two
0  Team_1   3
1  Team_2   3
2  Team_3   3

有人知道问题出在哪里吗?提前感谢!

试试这个:

df2['No_Two'] = list(map(lambda x:int(x[0])+int(x[1]) ,zip(df1['No_One'],df2['No_Two']))
print(df2)

相关内容

  • 没有找到相关文章

最新更新