Created
January 16, 2020 12:40
-
-
Save martimors/8e3dd2dc782a7cb187cc80953a5ea616 to your computer and use it in GitHub Desktop.
Convert all dates to string in pandas dataframe
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
def datetime_to_string(df): | |
""" | |
Convert all datetimes to strings in a dataframe. | |
Assumes dates are all timezone aware. | |
""" | |
datetime_columns = df.select_dtypes(include="datetimetz").columns.to_list() | |
for col in datetime_columns: | |
df[col] = df[col].dt.strftime(date_format="%Y-%m-%dT%H:%M:%S%z") | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment