Convert Timestamp to DateTime for Pandas DataFrame

Posted by in Software, Tutorial

To convert a pandas data frame value from unix timestamp to python datetime you need to use:

where:

  • timestamp is the column containing the timestamp value
  • unit='s' defines the unit of the timestamp (seconds in this case)

You can actually replace the column altogether:

Unfortunately, the conversion is not really aware of the time zone so, if you want to e.g. create a django module, you’ll need to make the datetime object aware:

Moreover, if you want to change to another timezone, you’ll need to:


A little experiment: If you find this post and ad below useful, please check the ad out :-)