gpt4 book ai didi

python - 了解与 Pandas 连接时使用 join_axes 的 FutureWarning

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

我有两个数据框:

df1:

A B C
1 A1 B1 C1
2 A2 B2 C2

df2:

B C D
3 B3 C3 D3
4 B4 C4 D4

两者的 B 列和 C 列相同。

我想垂直连接它们并保留第一个 DataFrame 的列:

pd.concat([df1, df2], join_axes=[df1.columns]):

A B C
1 A1 B1 C1
2 A2 B2 C2
3 NaN B3 C3
4 NaN B4 C4

这行得通,但引发了一个

FutureWarning: The join_axes-keyword is deprecated. Use .reindex or .reindex_like on the result to achieve the same functionality.

我找不到(无论是在文档中还是通过 Google)如何“在结果上使用 .reindex 或 .reindex_like 以实现相同的功能”。

说明问题的 Colab 笔记本:https://colab.research.google.com/drive/13EBq2z0Nh05JY7ovrdnLGtfeqdKVvZq0

最佳答案

就像错误提到的添加reindex

pd.concat([df1,df2.reindex(columns=df1.columns)])
Out[286]:
A B C
1 A1 B1 C1
2 A2 B2 C2
3 NaN B3 C3
4 NaN B4 C4

关于python - 了解与 Pandas 连接时使用 join_axes 的 FutureWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58564908/

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