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)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay