convert all date columns using pd datetime

Solutions on MaxInterview for convert all date columns using pd datetime by the best coders in the world

showing results for - "convert all date columns using pd datetime"
Imene
16 May 2019
1def lookup(s):
2    """
3    This is an extremely fast approach to datetime parsing.
4    For large data, the same dates are often repeated. Rather than
5    re-parse these, we store all unique dates, parse them, and
6    use a lookup to convert all dates.
7    """
8    dates = {date:pd.to_datetime(date) for date in s.unique()}
9    return s.apply(lambda v: dates[v])
10
11to_datetime: 5799 ms
12dateutil:    5162 ms
13strptime:    1651 ms
14manual:       242 ms
15lookup:        32 ms
16