Answers for "pandas convert all datetime columns to datetime dtypes"

15

convert column in pandas to datetime

df['col'] = pd.to_datetime(df['col'])
Posted by: Guest on April-16-2020
0

convert all date columns using pd.datetime

def lookup(s):
    """
    This is an extremely fast approach to datetime parsing.
    For large data, the same dates are often repeated. Rather than
    re-parse these, we store all unique dates, parse them, and
    use a lookup to convert all dates.
    """
    dates = {date:pd.to_datetime(date) for date in s.unique()}
    return s.apply(lambda v: dates[v])

to_datetime: 5799 ms
dateutil:    5162 ms
strptime:    1651 ms
manual:       242 ms
lookup:        32 ms
Posted by: Guest on May-30-2021

Code answers related to "pandas convert all datetime columns to datetime dtypes"

Python Answers by Framework

Browse Popular Code Answers by Language