Choosing a Dataframe row by weekday index in Python

I try to select every Friday in the daily stock price data frame. I read and tried the sentence in this link , in particular:

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

but I get the following error:

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

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

I believe the problem is that Python does not recognize rows in the index as dates, but I cannot understand why. DataFrame is as follows:

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

Any help is appreciated.

+4
source share
1 answer

to try:

df.index = df.index.to_datetime()
+3
source

Source: https://habr.com/ru/post/1529544/


All Articles