Member-only story

Managing Date, Datetime, and Timestamp in Python/Pandas

David Allen
4 min readSep 6, 2019

--

Personal documentation for managing date & time in python/pandas. This is a living document to assist analysis projects in Jupyter Notebook.

Table of Contents:

  1. What is today’s date?
  2. Timedeltas
  3. Convert Datetime to Date
  4. Create new [‘day’],[‘week’],[‘month’], or [‘year’]column from Datetime
  5. Convert String to Timestamp
  6. Convert String to Datetime
  7. Convert Dataframe String Date Column to Datetime
  8. Strip Date String Data
  9. Convert Timestamp to String
  10. Convert String Column to Datetime
  11. Convert Timestamp to Datetime
  12. Unix Date Modifiers

1. What is today’s date?

# gives timestamp of today's date at the time of cell execution
import pandas as pd
today = pd.to_datetime('today')

2. Timedeltas

# using timedelta on a datetime from datetime import timedeltatoday = pd.to_datetime('today')
last_week = today + timedelta(days=-7)
# this will return a timestamp

3. Convert Datetime to Date

--

--

David Allen
David Allen

Written by David Allen

Documentation and tutorials on Python, Pandas, Jupyter Notebook, and Data Analysis.

Responses (1)