Skip to content

Instantly share code, notes, and snippets.

@mickaellegal
Created August 7, 2014 09:10
Show Gist options
  • Save mickaellegal/6a7824452275db584a00 to your computer and use it in GitHub Desktop.
Save mickaellegal/6a7824452275db584a00 to your computer and use it in GitHub Desktop.
Python: Cleaning dates
import pandas as pd
import numby as np
# import your csv file into a pandas dataframe
df = pd.DataFrame('YOUR_FILE.csv')
# convert the column with the date to a date format
date = pd.to_datetime(df.date_column)
# Change the format of the date
dates_clean = pd.DataFrame(date.map(lambda x: x.strftime('%Y-%m-%d')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment