Sometimes convenience becomes a handicap. Saw this first hand later last month.
Was so used to using Pandas DataFrame and the Timeindex object that when I had to move back to a system which didn’t have pandas I was struggling to get a simplified day of year, day of week and week of year from python’s standard datetime module.
Here is how all this available in Pandas from a Timeindex column or index.
If your looks like this, with index as time
You can get all the convenience functions like this
However, this gave an opportunity to explore datetime and here is the code to get all this and more from date time.
import datetime today=datetime.datetime.today() day_of_year = today.timetuple().tm_yday weekofyear=today.isocalendar() dayofweek=today.isocalendar()
Inconveniences are good; they always end up teaching you something.