Question

I am trying to select every Friday in a dataframe of daily stock price closes. I read and tried the suggestion in this link, specifically:

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 issue is that Python does not recognize the strings in the index as dates, but I can't figure out why. The DataFrame looks like this:

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

Any help is appreciated.

Was it helpful?

Solution

try:

df.index = df.index.to_datetime()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top