October 2017
Intermediate to advanced
532 pages
16h 10m
English
The date formatting directive can actually make quite a large difference when converting a large sequence of strings to Timestamps. Whenever pandas uses to_datetime to convert a sequence of strings to Timestamps, it searches a large number of different string combinations that represent dates. This is true even if all the strings have the same format. With the format parameter, we can specify the exact date format, so that pandas doesn't have to search for the correct one each time. Let's create a list of dates as strings and time their conversion to Timestamps both with and without a formatting directive:
>>> date_string_list = ['Sep 30 1984'] * 10000>>> %timeit pd.to_datetime(date_string_list, format='%b %d %Y')35.6 ms ± ...
Read now
Unlock full access