I’m having a DataFrame with a date column. How can I map each date d
to the start day of the week containing d
?
Advertisement
Answer
import pandas as pd df['Date'] - pd.to_timedelta(df['Date'].dt.dayofweek, unit='d')
I’m having a DataFrame with a date column. How can I map each date d
to the start day of the week containing d
?
import pandas as pd df['Date'] - pd.to_timedelta(df['Date'].dt.dayofweek, unit='d')