Selecting rows with a certain weekday in DataFrame in Python
You can get the weekday by df.index.weekday
, note that Monday = 0
and Sunday = 6
To select the rows on Monday, you can do
df = df[df.index.weekday==0]
Here "Date" is the column name. Creating new column "weekday"
df["weekday"] = pd.to_datetime(df.Date).dt.dayofweek
From this column you can select any weekday from dataframe
df.loc[df["weekday"] ==6]
Here 6 denotes "Sunday"