【问题标题】:Concatenate/Join/Merge two Dataframes with one missing column连接/加入/合并两个缺少一列的数据框
【发布时间】:2020-05-07 09:58:36
【问题描述】:

我知道这个问题可能已经被问过了,但我检查了所有问题,我认为我的情况有所不同(请客气)。所以我有 2 个数据集,第一个是测试数据集,第二个是我保存在数据框中的预测(预测值,这就是没有数据列的原因)。我想合并两者并拥有一个像我发布的第二张图片中的数据框。 关于日期栏......我可以在这里使用任何提示/技巧吗? 谢谢

这是我的代码行

result = pd.concat([test_df, pred_df], axis=1).reindex(test_df.index)
result

【问题讨论】:

    标签: python pandas date merge concatenation


    【解决方案1】:

    问题很可能是因为您的数据框具有不同的索引。 做:

    pred_df.index = test_df.index
    result = pd.concat([test_df, pred_df], axis=1).reindex(test_df.index)
    

    【讨论】:

    • 谢谢...我离我更近了(但在我的脑海里,哈哈)。我正在考虑处理索引,但我不知道如何处理。谢谢
    猜你喜欢
    • 2021-11-13
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 2014-03-23
    • 2017-06-08
    相关资源
    最近更新 更多