Working with date and time
In time series analysis, you may spend a great deal of time transforming and manipulating date and time columns. This includes parsing dates when upon reading a file, casting strings to date, extracting information from date columns, and utilizing temporal expressions.
Also, it’s good to remember that we have time zones across the globe. We’ll learn how to work with time zones in this recipe as well.
How to do it...
Here are a few things that may be helpful when working with date and time:
- If your source data has a date, datetime, or time column of the
string
date type, you may be able to use thetry_parse_date
parameter to convert it to thedate
/datetime
/time
data type upon reading.Let’s add the parameter to the
scan_csv()
method:lf_date_parsed = pl.scan_csv('../data/toronto_weather.csv', try_parse_dates=True) lf_date_parsed.head().collect()
The preceding code will return the following output:
...