【问题标题】:Panda's Joining two series by Day熊猫每天加入两个系列
【发布时间】:2015-04-18 19:14:24
【问题描述】:

如果日期完全对齐,通常我们可以简单地运行df1.join(df2)。但是在我的数据集中,我与索引略有不匹配。

df1 中的pandas.tseries.index.DatetimeIndex 格式为2004-07-07 20:00:00, 2004-07-08 20:00:00...df2pandas.tseries.index.DatetimeIndex 格式为2004-07-07, 2004-07-08,...

我想忽略小时分钟和秒并加入这两个data frames。不会引发错误,但会为来自 df2 的列在 2004-07-08 20:00:00 上显示 NaN 值。如何加入这两个数据框?

【问题讨论】:

    标签: python datetime pandas


    【解决方案1】:

    我认为最简单的解决方案是重新格式化一个或两个数据框的日期时间列。假设时间对您不重要,也许您可​​以从第一个数据框中删除时间。 Here's a post which uses normalize to achieve this.

    【讨论】:

    • 真棒不知道normalize。解决方法很简单,df.index = df.index.normalize()
    猜你喜欢
    • 2016-04-23
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    相关资源
    最近更新 更多