【问题标题】:No longer possible to index a pandas DatetimeIndex with a date?不再可以用日期索引 pandas DatetimeIndex?
【发布时间】:2020-07-30 21:09:51
【问题描述】:

我刚刚从 0.24 升级到 pandas 1.1,我觉得我疯了。您真的不能再用日期来索引 DatetimeIndex 吗?

#This now fails!
import datetime as dt
s = pd.Series([1,2], pd.DatetimeIndex([dt.date(2020,1,1),dt.date(2020,1,2)]))
s.loc[dt.date(2020,1,2)]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-49-18ac6239cd3a> in <module>
      1 s = pd.Series([1,2], pd.DatetimeIndex([dt.date(2020,1,1),dt.date(2020,1,2)]))
----> 2 s.loc[dt.date(2020,1,2)]
....

请告诉我我错了!

【问题讨论】:

  • 什么是dt?我假设它是import datetime as dt,但如果我这样做,你的代码对我有用
  • 请什么版本的熊猫?

标签: pandas date datetimeindex


【解决方案1】:

这是一个将在 1.1.1 中修复的错误

https://github.com/pandas-dev/pandas/issues/35466

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 2016-12-05
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    • 2016-05-07
    相关资源
    最近更新 更多