4

我试图在每日收盘价的数据框中选择每个星期五。我阅读并尝试了此链接中的建议,特别是:

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

任何帮助表示赞赏。

4

1 回答 1

3

尝试:

df.index = df.index.to_datetime()
于 2014-03-01T13:33:18.360 回答