shape: (4, 1)
| Date |
|---|
| date |
| 0999-12-31 |
| 1897-05-07 |
| 1945-01-01 |
| 2025-01-01 |
dt.century
Joram Mutenge
2025-11-23
You are querying a historical database that contains dates, and you want to create another column that indicates the century for each date. The dataframe below shows a set of example dates.
| Date |
|---|
| date |
| 0999-12-31 |
| 1897-05-07 |
| 1945-01-01 |
| 2025-01-01 |
To extract the century from a date value, use the Polars expression dt.century like this:
| Date | Century |
|---|---|
| date | i32 |
| 0999-12-31 | 10 |
| 1897-05-07 | 19 |
| 1945-01-01 | 20 |
| 2025-01-01 | 21 |
Check out my Polars course to learn more.