如何合并两个具有相同索引的 pandas DataFrame
如果你有两个要连接的 pandas DataFrame,其中两个 DataFrame 的 index 相同,并且你想获得一个 DataFrame,如果相应 DataFrame 没有值,则相应列设置为 NaN,这通常是正确的做法:
concat_dataframes.py
df_compare = pd.concat([df1, df2], axis=1, join='outer')如果你只想在两个 DataFrame 都有某些值的地方保留值,使用 join='outer'
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow