https://github.com/pola-rs/polars-xdt
Polars plugin offering eXtra stuff for DateTimes
https://github.com/pola-rs/polars-xdt
polars
Last synced: 7 months ago
JSON representation
Polars plugin offering eXtra stuff for DateTimes
- Host: GitHub
- URL: https://github.com/pola-rs/polars-xdt
- Owner: pola-rs
- License: mit
- Created: 2023-10-11T10:33:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-25T13:06:24.000Z (about 1 year ago)
- Last Synced: 2024-05-01T16:42:40.913Z (about 1 year ago)
- Topics: polars
- Language: Python
- Homepage: https://marcogorelli.github.io/polars-xdt-docs/
- Size: 34 MB
- Stars: 152
- Watchers: 4
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-polars - polars-xdt - Polars plugin with extra-datetime-related functionalities by [@MarcoGorelli](https://github.com/MarcoGorelli). (Libraries/Packages/Scripts / Polars plugins)
README
# polars-xdt
## eXtra stuff for DateTimes
![]()
[](https://badge.fury.io/py/polars-xdt)
[](https://marcogorelli.github.io/polars-xdt-docs/)eXtra stuff for DateTimes in [Polars](https://www.pola.rs/).
- ✅ blazingly fast, written in Rust
- ✅ convert to and from multiple time zones
- ✅ format datetime in different locales
- ✅ convert to Julian Dates
- ✅ ~time-based EWMA~ (upstreamed to Polars itself)
- ✅ ~custom business-day arithmetic~ (upstreamed to Polars itself)Installation
------------First, you need to [install Polars](https://pola-rs.github.io/polars/user-guide/installation/).
Then, you'll need to install `polars-xdt`:
```console
pip install polars-xdt
```Read the [documentation](https://marcogorelli.github.io/polars-xdt-docs/) for a more examples and functionality.
Basic Example
-------------
Say we start with
```python
from datetime import datetimeimport polars as pl
import polars_xdt as xdtdf = pl.DataFrame(
{
"local_dt": [
datetime(2020, 10, 10, 1),
datetime(2020, 10, 10, 2),
datetime(2020, 10, 9, 20),
],
"timezone": [
"Europe/London",
"Africa/Kigali",
"America/New_York",
],
}
)
```Let's localize each datetime to the given timezone and convert to
UTC, all in one step:```python
result = df.with_columns(
xdt.from_local_datetime(
"local_dt", pl.col("timezone"), "UTC"
).alias("date")
)
print(result)
```
```
shape: (3, 3)
┌─────────────────────┬──────────────────┬─────────────────────────┐
│ local_dt ┆ timezone ┆ date │
│ --- ┆ --- ┆ --- │
│ datetime[μs] ┆ str ┆ datetime[μs, UTC] │
╞═════════════════════╪══════════════════╪═════════════════════════╡
│ 2020-10-10 01:00:00 ┆ Europe/London ┆ 2020-10-10 00:00:00 UTC │
│ 2020-10-10 02:00:00 ┆ Africa/Kigali ┆ 2020-10-10 00:00:00 UTC │
│ 2020-10-09 20:00:00 ┆ America/New_York ┆ 2020-10-10 00:00:00 UTC │
└─────────────────────┴──────────────────┴─────────────────────────┘
```Read the [documentation](https://marcogorelli.github.io/polars-xdt-docs/) for more examples!
Logo
----Thanks to [Olha Urdeichuk](https://www.fiverr.com/olhaurdeichuk) for the illustration.