Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Date Utility Library

Is there a library in python that can produce date dimensions given a certain day? I'd like to use this for data analysis. Often I have a time series of dates, but for aggregation purposes I'd like to be able to quickly produce dates associated with that day - like first date of month, first day in week, and the like.

I think I could create my own, but if there is something out there already it'd be nice.

Thanks

like image 341
tshauck Avatar asked Jan 17 '23 07:01

tshauck


1 Answers

Have a look at dateutil.

The recurrence rules and relative deltas are what you want.

For example, if you wanted to get last monday:

import dateutil.relativedelta as rd
import datetime

last_monday = datetime.date.today() + rd.relativedelta(weekday=rd.MO(-1))
like image 199
Joe Kington Avatar answered Jan 19 '23 21:01

Joe Kington