Choosing rows with a specific day of the week in a DataFrame in Python

I have a DataFrame with a time index like:

df.index = [2013-09-09 06:23:18, 2013-09-10 07:09:05, ..., 2014-02-02 06:04:04]

How can I select rows on a specific weekday, for example, on Monday? Then I will not have lines on other weekdays. Any help was appreciated.

+5
source share
1 answer

You can get the day of the week by df.index.weekday, note that Monday = 0andSunday = 6

To select rows on monday you can do

df = df[df.index.weekday==0]
+7
source

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


All Articles