Polars ile Veri Dönüşümü
Liam Brannigan
Data Scientist & Polars Contributor




shape: (24, 3)
| time | price | solar |
| --- | --- | --- |
| str | f64 | f64 |
|------------------|-------|-------|
| 05/07/2025 00:00 | 34.2 | 0.0 |
| ... | ... | ... |
| 05/07/2025 12:00 | 0.0 | 462.0 |
time - saatlik değerlerprice - MWh başına £solar - metrekare başına W

Date - takvim tarihi - 2000-01-01Datetime - tarih ve saat - 2000-01-01 12:00:00Time - günün saati - 12:00:00Duration - süre - 3 hourspl.read_csv(
"electricity_prices",
)
pl.read_csv(
"electricity_prices",
try_parse_dates=True
)
YYYY-MM-DD2025-07-052025-07-05 12:00:00| time | price | solar |
| --- | --- | --- |
| str | f64 | f64 |
|------------------|-------|-------|
| 05/07/2025 00:00 | 34.2 | 0.0 |
| 05/07/2025 01:00 | 28.7 | 0.0 |
DD/MM/YYYY HH:MMprices.with_columns(
pl.col("time").str.strptime( )
)
prices.with_columns(
pl.col("time").str.strptime(pl.Datetime, )
)
prices.with_columns(
pl.col("time").str.strptime(pl.Datetime, "%d/%m/%Y ")
)
prices.with_columns(
pl.col("time").str.strptime(pl.Datetime, "%d/%m/%Y %H:%M")
)
prices.with_columns(
pl.col("time").str.strptime(pl.Datetime, "%d/%m/%Y %H:%M")
)
| time | price | solar |
| --- | --- | --- |
| datetime[us] | f64 | f64 |
|---------------------|-------|-------|
| 2025-07-05 00:00:00 | 34.2 | 0.0 |
| 2025-07-05 01:00:00 | 28.7 | 0.0 |
| 2025-07-05 02:00:00 | 27.5 | 0.0 |




prices.with_columns(
pl.col("time").dt.date()
)
prices.with_columns(
pl.col("time").dt.date().alias("date")
)
prices.with_columns(
pl.col("time").dt.date().alias("date")
)
| time | price | solar | date |
| --- | --- | --- | --- |
| datetime[µs] | f64 | f64 | date |
|---------------------|-------|-------|------------|
| 2025-07-05 00:00:00 | 34.2 | 0.0 | 2025-07-05 |
| 2025-07-05 01:00:00 | 28.7 | 0.0 | 2025-07-05 |
| 2025-07-05 02:00:00 | 27.5 | 0.0 | 2025-07-05 |
prices.with_columns(
pl.col("time").dt.time().alias("time_of_day")
)
prices.with_columns(
pl.col("time").dt.time().alias("time_of_day")
)
| time | price | solar | time_of_day |
| --- | --- | --- | --- |
| datetime[us] | f64 | f64 | time |
|---------------------|-------|-------|-------------|
| 2025-07-05 00:00:00 | 34.2 | 0.0 | 00:00:00 |
| 2025-07-05 01:00:00 | 28.7 | 0.0 | 01:00:00 |
| 2025-07-05 02:00:00 | 27.5 | 0.0 | 02:00:00 |
prices.with_columns(
pl.col("time").dt.hour().alias("hour")
)
prices.with_columns(
pl.col("time").dt.hour().alias("hour")
)
| time | price | solar | hour |
| --- | --- | --- | --- |
| datetime[µs] | f64 | f64 | i8 |
|---------------------|-------|-------|------|
| 2025-07-05 00:00:00 | 34.2 | 0.0 | 0 |
| 2025-07-05 01:00:00 | 28.7 | 0.0 | 1 |
| 2025-07-05 12:00:00 | 0.0 | 462.0 | 12 |
.dt.year() - yılı çıkarır.dt.month() - ayı çıkarır (1-12).dt.day() - ayın gününü çıkarır.dt.minute() - dakikayı çıkarır.dt.offset_by() - datetime'ları ayarlar"1h" - 1 saat ileri"-2d" - 2 gün geri.dt.offset_by() - datetime'ları ayarlar"1h" - 1 saat ileri"-2d" - 2 gün geriprices.with_columns(
pl.col("time").dt.offset_by("1h")
)
prices.with_columns(
pl.col("time").dt.offset_by("1h").alias("time_end")
)
prices.with_columns(
pl.col("time").dt.offset_by("1h").alias("time_end")
)
| time | price | solar | time_end |
| --- | --- | --- | --- |
| datetime[µs] | f64 | f64 | datetime[µs] |
|---------------------|-------|-------|---------------------|
| 2025-07-05 00:00:00 | 34.2 | 0.0 | 2025-07-05 01:00:00 |
| 2025-07-05 01:00:00 | 28.7 | 0.0 | 2025-07-05 02:00:00 |
| 2025-07-05 02:00:00 | 27.5 | 0.0 | 2025-07-05 03:00:00 |
Polars ile Veri Dönüşümü