If you need to convert string to dates in Python and Pandas you can check:
How to Convert String to DateTime in Pandas
It contains basic date conversion like:
pd.to_datetime(df['date']) plus extra examples like:
- custom date and time patterns
- infer date pattern
- dates different language locales
- different date formats
pd.to_datetime(df['date'] , format='%Y%m%d HH:MM:SS', errors='ignore') Also it will show if a given string contains dates with fuzzy matching.
Or mixed dates in a Pandas column:
if '/' in date: return pd.to_datetime(date, format = '%Y/%m/%d') elif '-' in date: return pd.to_datetime(date, format = '%d-%m-%Y') else: return pd.to_datetime(date, format = '%d.%m.%Y')
Top comments (0)