Convert String to Date in Pandas and Python

If you need to convert string to dates in Python and Pandas you can check:

It contains basic date conversion like:

pd.to_datetime(df['date'])

plus extra examples like:

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')
Exit mobile version