【问题标题】:Dataframe Row Selection by Weekday of Index in PythonPython中索引的工作日数据框行选择
【发布时间】:2014-04-02 13:51:20
【问题描述】:

我试图在每日收盘价的数据框中选择每个星期五。我阅读并尝试了this link 中的建议,具体来说:

Fridays = df[df.index.weekday == 4] #Fridays

但我收到以下错误:

AttributeError: 'Index' object has no attribute 'weekday'

<class 'pandas.core.frame.DataFrame'>

我认为问题在于 Python 无法将索引中的字符串识别为日期,但我不知道为什么。 DataFrame 如下所示:

1993-04-08    3387.83
1993-04-12    3420.79

感谢任何帮助。

【问题讨论】:

    标签: python indexing pandas dataframe weekday


    【解决方案1】:

    尝试:

    df.index = df.index.to_datetime()
    

    【讨论】:

      猜你喜欢
      • 2018-12-25
      • 2017-04-01
      • 2021-07-13
      • 1970-01-01
      • 2020-04-27
      • 1970-01-01
      • 2021-10-10
      • 2015-03-11
      • 2019-02-10
      相关资源
      最近更新 更多