'How to get week start date (Sunday) from Date column in python

I have been trying to get week start date from Sunday but not able to get that by using lambda:

lite['week_start']=lite['invoice_date.1'].dt.to_period('W').apply(lambda r: r.start_time)


Solution 1:[1]

Check the pd.to_period documentation: there you will find a link for pandas’ offset strings

https://pandas.pydata.org/docs/user_guide/timeseries.html#timeseries-offset-aliases

Look for Anchored offsets:

W-SUN weekly frequency (Sundays). Same as W

W-SAT will do it for you:

lite['week_start'] = lite['invoice_date.1'].dt.to_period('W-SAT').apply(lambda r: r.start_time)

Week ends on Saturday and begins on Sunday.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 guardian