DEV Community

Cover image for Convert String to Date in Pandas and Python
Softhints
Softhints

Posted on

3 3

Convert String to Date in Pandas and Python

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'])
Enter fullscreen mode Exit fullscreen mode

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')
Enter fullscreen mode Exit fullscreen mode

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')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay