Panda Time index vs DateTime and Inconveniences

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
day_of_year = today.timetuple().tm_yday

Inconveniences are good; they always end up teaching you something.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s