gpt4 book ai didi

python-2.7 - python , Pandas : replacing values in one DF by same-index values from another DF

转载 作者:行者123 更新时间:2023-12-04 01:56:36 25 4
gpt4 key购买 nike

我有两个索引完全相同的数据框:

the first one:
0 1 2
2 0.011765 0.490196 0.015686
2 0.011765 0.490196 0.015686
2 0.007843 0.494118 0.007843
2 0.007843 0.494118 0.007843
2 0.007843 0.501961 0.011765
.. ... ... ...

0 0.000000 0.031373 0.039216
0 0.031373 0.082353 0.105882
0 0.094118 0.149020 0.192157
0 0.094118 0.156863 0.215686

[337962 rows x 3 columns]

第二个:

          0         1         2
0 0.055852 0.118138 0.052386
1 0.453661 0.665857 0.441551
2 0.096394 0.635641 0.068524
3 0.952545 0.827438 0.047632
4 0.787729 0.823494 0.795792
5 0.050284 0.549379 0.592593
6 0.608805 0.215458 0.068293
7 0.775640 0.091352 0.689224

第一个 DF 相当大。我需要尽快用小 DF 中具有相同索引的值替换大 DF 中的值。如何?感谢您的帮助。

最佳答案

使用第二个dataframe的索引对第一个dataframe进行分片然后赋值。

df1.loc[df2.index] = df2

关于python-2.7 - python , Pandas : replacing values in one DF by same-index values from another DF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35380010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com