Zamana göre filtreleme ve özetleme

Polars ile Veri Dönüşümü

Liam Brannigan

Data Scientist & Polars Contributor

Belirli fiyatları bulma

Zaman serisi tablosu

Polars ile Veri Dönüşümü

Belirli fiyatları bulma

1 satırı vurgulanmış zaman serisi tablosu

Polars ile Veri Dönüşümü

Belirli fiyatları bulma

3 satırı vurgulanmış zaman serisi tablosu

Polars ile Veri Dönüşümü

pl.datetime ile filtreleme

prices.filter(

)

$$

$$

$$

$$

  • Görev: 5 Temmuz öğlen fiyatlarını bulun
Polars ile Veri Dönüşümü

pl.datetime ile filtreleme

prices.filter(
    pl.col("time") == 
)
Polars ile Veri Dönüşümü

pl.datetime ile filtreleme

prices.filter(
    pl.col("time") == pl.datetime(                                  )
)
Polars ile Veri Dönüşümü

pl.datetime ile filtreleme

prices.filter(
    pl.col("time") == pl.datetime(year=2025, month=7, day=5, hour=12)
)
| time                | price | solar |
| ---                 | ---   | ---   |
| datetime[µs]        | f64   | f64   |
|---------------------|-------|-------|
| 2025-07-05 12:00:00 | 0.0   | 462.0 |
Polars ile Veri Dönüşümü

pl.date ile tarihe göre filtreleme

prices.filter(
    pl.col("time").dt.date() == 
)
Polars ile Veri Dönüşümü

pl.date ile tarihe göre filtreleme

prices.filter(
    pl.col("time").dt.date() == pl.date(year=2025, month=7, day=5)
)
Polars ile Veri Dönüşümü

pl.date ile tarihe göre filtreleme

prices.filter(
    pl.col("time").dt.date() == pl.date(year=2025, month=7, day=5)
)
| time                | price | solar |
| ---                 | ---   | ---   |
| datetime[µs]        | 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 23:00:00 | 72.3  | 0.0   |
Polars ile Veri Dönüşümü

Tarih-saat aralığı filtreleme

prices.filter(
    pl.col("time").is_between(


    )
)
Polars ile Veri Dönüşümü

Tarih-saat aralığı filtreleme

prices.filter(
    pl.col("time").is_between(
        pl.datetime(2025, 7, 5, 8),
        pl.datetime(2025, 7, 5, 18)
    )
)
Polars ile Veri Dönüşümü

Tarih-saat aralığı filtreleme

prices.filter(
    pl.col("time").is_between(
        pl.datetime(2025, 7, 5, 8),
        pl.datetime(2025, 7, 5, 18)
    )
)
| time                | price | solar |
| ---                 | ---   | ---   |
| datetime[µs]        | f64   | f64   |
|---------------------|-------|-------|
| 2025-07-05 08:00:00 | 1.7   | 180.0 |
| 2025-07-05 09:00:00 | 1.3   | 243.0 |
| ...                 | ...   | ...   |
| 2025-07-05 17:00:00 | 77.8  | 153.0 |
| 2025-07-05 18:00:00 | 87.3  | 119.0 |
Polars ile Veri Dönüşümü

Zamana göre özetleme

Zaman pencerelerine özetlenecek satırlar

  • Verileri .group_by_dynamic() ile özetleyin
Polars ile Veri Dönüşümü

Zamana göre özetleme

prices.sort("time")


Polars ile Veri Dönüşümü

Zamana göre özetleme

prices.sort("time").group_by_dynamic("time",          )


Polars ile Veri Dönüşümü

Zamana göre özetleme

prices.sort("time").group_by_dynamic("time", every="6h")


Polars ile Veri Dönüşümü

6 saatlik pencerelerle özetleme

prices.sort("time").group_by_dynamic("time", every="6h").agg(

)
Polars ile Veri Dönüşümü

6 saatlik pencerelerle özetleme

prices.sort("time").group_by_dynamic("time", every="6h").agg(
    pl.col("price").mean().alias("avg_price")
)
Polars ile Veri Dönüşümü

6 saatlik pencerelerle özetleme

prices.sort("time").group_by_dynamic("time", every="6h").agg(
    pl.col("price").mean().alias("avg_price")
)
| time                | avg_price |
| ---                 | ---       |
| datetime[µs]        | f64       |
|---------------------|-----------|
| 2025-07-05 00:00:00 | 28.4      |
| 2025-07-05 06:00:00 | 15.2      |
| 2025-07-05 12:00:00 | 42.1      |
| 2025-07-05 18:00:00 | 68.7      |
Polars ile Veri Dönüşümü

Güne göre özetleme

prices.sort("time").group_by_dynamic("time", every="1d").agg(

pl.col("price").mean().alias("avg_price"), pl.col("solar").mean().alias("avg_solar")
)
Polars ile Veri Dönüşümü

Güne göre özetleme

prices.sort("time").group_by_dynamic("time", every="1d").agg(
    pl.col("price").mean().alias("avg_price"),
    pl.col("solar").mean().alias("avg_solar")
)
| time                | avg_price | avg_solar |
| ---                 | ---       | ---       |
| datetime[µs]        | f64       | f64       |
|---------------------|-----------|-----------|
| 2025-07-05 00:00:00 | 36.7      | 147.1     |
| 2025-07-06 00:00:00 | 42.1      | 133.8     |
Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

  • every - yeni pencerenin başlama sıklığı
  • period - her pencerenin süresi
  • Varsayılan olarak period, every ile aynıdır
Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

prices.group_by_dynamic("time", every="2h")
Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

Çakışmayan 2 saatlik pencereler

Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

prices.group_by_dynamic("time", every="1h", period="2h")
Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

10'da başlayan ilk çakışan pencere

Polars ile Veri Dönüşümü

Pencere boyutunu kontrol etme

11'de başlayan ikinci çakışan pencere

Polars ile Veri Dönüşümü

Haydi pratik yapalım!

Polars ile Veri Dönüşümü

Preparing Video For Download...