Skip to content

Instantly share code, notes, and snippets.

@CharlyWargnier
Created February 8, 2020 17:07
Show Gist options
  • Save CharlyWargnier/7bde8b2b79ffcd59488df55f9ed6cbbc to your computer and use it in GitHub Desktop.
Save CharlyWargnier/7bde8b2b79ffcd59488df55f9ed6cbbc to your computer and use it in GitHub Desktop.
# Split Date & Time
df[['Date_Time', 'header']] = df['header'].str.split("\] ", 1,
expand=True)
df['Date_Time'] = df['Date_Time'].str.replace(':.*', '')
# Convert the Date_Time column from string to datetime format
df['Date'] = pd.to_datetime(df['Date_Time'], errors='coerce',
infer_datetime_format=True)
# Remove Time column, for clarity's sake
df = df.drop(['Date_Time'], axis=1)
# Check that the Date column has been converted to a time series
df.info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment