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
JavaScript
x
3
1
import pandas as pd
2
df['Date'] - pd.to_timedelta(df['Date'].dt.dayofweek, unit='d')
3
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')