Member-only story
Managing Date, Datetime, and Timestamp in Python/Pandas
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:
- What is today’s date?
- Timedeltas
- Convert Datetime to Date
- Create new [‘day’],[‘week’],[‘month’], or [‘year’]column from Datetime
- Convert String to Timestamp
- Convert String to Datetime
- Convert Dataframe String Date Column to Datetime
- Strip Date String Data
- Convert Timestamp to String
- Convert String Column to Datetime
- Convert Timestamp to Datetime
- Unix Date Modifiers
1. What is today’s date?
# gives timestamp of today's date at the time of cell execution
import pandas as pdtoday = 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