作者:彭润昕_149 | 来源:互联网 | 2023-10-13 12:05
I have a large python script, which makes two dataframes A and B, and at the end, I want to fill in dataframe A with the values of dataframe B, and keep the columns of dataframe A, but it is not going well.
我有一个大的python脚本,它使两个dataframes a和B,在最后,我想用dataframe B的值填充dataframe a,并保留dataframe a的列,但是它不太顺利。
Dataframe A is like this
Dataframe A就像这样。
A B C D
1 ab
2 bc
3 cd
Dataframe B:
A BB CC
1 C 10
2 C 11
3 D 12
My output must be:
我的输出必须:
new dataframe
新dataframe
A B C D
1 ab 10
2 bc 11
3 cd 12
But my output is
但我的输出是
A B C D
1 ab
2 bc
3 cd
Why is it not filling in the values of dataframe B? My command is
为什么不填充dataframe B的值?我的命令是
dfnew = dfB.pivot_table(index='A', columns='BB', values='CC').reindex(index=dfA.index, columns=dfA.columns).fillna(dfA)
1 个解决方案