gpt4 book ai didi

python - 使用来自另一个数据框的行号,从现有数据框创建新的 pandas 数据框

转载 作者:太空宇宙 更新时间:2023-11-03 23:51:51 25 4
gpt4 key购买 nike

所以我有一个这样的数据框,我们称它为 df1:

       Column1   Column2   Column3  
1258 .51 .38 .12

2674 .76 .21 .45

3098 .89 .34 .19

6012 .91 .78 .67

然后我还有另一个数据框,我们称它为 df2,大约有 10000 行。

       a    b   c   d
0 0 1 0 0
1 1 1 1 0
2 0 0 0 1
3 0 0 1 1
...
10000 1 1 0 1

有没有一种方法可以使用 df1 中的行号从 df2 创建一个新数据框?所以输出数据框将是这样的:

      a   b   c   d
1258 0 1 0 1
2674 1 0 0 1
3098 0 1 1 1
6012 1 0 0 0

最佳答案

IIUC,这是loc

df2.loc[df1.index]

关于python - 使用来自另一个数据框的行号,从现有数据框创建新的 pandas 数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59143115/

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