I want to find out the following:
given a date (datetime
object), what is the corresponding day of the week?
For instance, Sunday is the first day, Mond
If you want to generate a column with a range of dates (Date
) and generate a column that goes to the first one and assigns the Week Day (Week Day
), do the following (I will used the dates ranging from 2008-01-01
to 2020-02-01
):
import pandas as pd
dr = pd.date_range(start='2008-01-01', end='2020-02-1')
df = pd.DataFrame()
df['Date'] = dr
df['Week Day'] = pd.to_datetime(dr).weekday
The output is the following:
The Week Day
varies from 0 to 6, where 0 corresponds to Monday and 6 to Sunday.