Created
November 16, 2018 09:15
-
-
Save Dih5/3b7f82aa9584eb5958b5d6bf50034405 to your computer and use it in GitHub Desktop.
Reformat a date in a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pandas as pd | |
original_format='%Y-%m-%d %H:%M:%S' | |
target_format='%d-%m-%y %H:%M' | |
attribute_name='Date' | |
file_path='ACertainFile.csv' | |
df=pd.read_csv(file_path) | |
df[attribute_name]=pd.to_datetime(df[attribute_name], format=original_format).apply(lambda x: x.strftime(target_format)) | |
df.to_csv("cleaned-"+file_path,index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment