Koşullu ifadeler oluşturma

Polars ile Veri Dönüşümü

Liam Brannigan

Data Scientist & Polars Contributor

Puan kalitesine göre sınıflandırma

shape: (5, 5)
| business         | location        | type       | rating | capacity |
| ---              | ---             | ---        | ---    | ---      |
| str              | str             | str        | i64    | i64      |
|------------------|-----------------|------------|--------|----------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       |
| Costa Coffee     | City Point      | café       | 5      | 41       |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
  • Görev: yüksek puanlı restoranları belirleyin
Polars ile Veri Dönüşümü

Puan kalitesine göre sınıflandırma

ratings.with_columns(


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

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(                     )

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

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("rating") == 5)

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

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Çok Yüksek Puan"))

)

$$

$$

  • pl.lit() ile sütun adı değil, sabit bir değer verin
Polars ile Veri Dönüşümü

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Çok Yüksek Puan"))
    .otherwise(pl.lit("Geliştirilmesi Gerek"))
)
Polars ile Veri Dönüşümü

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Çok Yüksek Puan"))
    .otherwise(pl.lit("Geliştirilmesi Gerek")).alias("quality")
)
Polars ile Veri Dönüşümü

Puan kalitesine göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Çok Yüksek Puan"))
    .otherwise(pl.lit("Geliştirilmesi Gerek")).alias("quality")
)
shape: (5, 6)
| business         | location        | type       | rating | capacity | quality            |
| ---              | ---             | ---        | ---    | ---      | ---                |
| str              | str             | str        | i64    | i64      | str                |
|------------------|-----------------|------------|--------|----------|--------------------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       | Çok Yüksek Puan    |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       | Geliştirilmesi Gerek |
| ...              | ...             | ...        | ...    | ...      | ...                |
Polars ile Veri Dönüşümü

Mekân büyüklüğüne göre sınıflandırma

shape: (5, 5)
| business         | location        | type       | rating | capacity |
| ---              | ---             | ---        | ---    | ---      |
| str              | str             | str        | i64    | i64      |
|------------------|-----------------|------------|--------|----------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       |
| Costa Coffee     | City Point      | café       | 5      | 41       |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
  • Görev: restoranları kapasiteye göre filtreleyin
Polars ile Veri Dönüşümü

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(



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

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100)


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

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Büyük"))


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

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Büyük"))
    .when(pl.col("capacity") >= 20)

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

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Büyük"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Orta"))

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

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Büyük"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Orta"))
    .otherwise(pl.lit("Küçük"))
)
Polars ile Veri Dönüşümü

Mekân büyüklüğüne göre sınıflandırma

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Büyük"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Orta"))
    .otherwise(pl.lit("Küçük")).alias("venue_size")
)
shape: (3, 6)
| business         | location        | type       | rating | capacity | venue_size |
| ---              | ---             | ---        | ---    | ---      | ---        |
| str              | str             | str        | i64    | i64      | str        |
|------------------|-----------------|------------|--------|----------|------------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       | Orta       |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        | Küçük      |
| The Queens Head  | Denman St.      | bar        | 5      | 187      | Büyük      |
Polars ile Veri Dönüşümü

İşletme türlerini standartlaştırma

shape: (5, 5)
| business         | location        | type       | rating | capacity |
| ---              | ---             | ---        | ---    | ---      |
| str              | str             | str        | i64    | i64      |
|------------------|-----------------|------------|--------|----------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       |
| Costa Coffee     | City Point      | café       | 5      | 41       |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
  • Görev: type sütununu standartlaştırın
Polars ile Veri Dönüşümü

İşletme türlerini standartlaştırma

ratings.with_columns(
    pl.col("type")
)
Polars ile Veri Dönüşümü

İşletme türlerini standartlaştırma

ratings.with_columns(
    pl.col("type").replace(                    )
)
Polars ile Veri Dönüşümü

İşletme türlerini standartlaştırma

ratings.with_columns(
    pl.col("type").replace("café", "restaurant")
)
shape: (5, 5)
| business         | location        | type       | rating | capacity |
| ---              | ---             | ---        | ---    | ---      |
| str              | str             | str        | i64    | i64      |
|------------------|-----------------|------------|--------|----------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       |
| Costa Coffee     | City Point      | restaurant | 5      | 41       |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
Polars ile Veri Dönüşümü

Hadi pratik yapalım!

Polars ile Veri Dönüşümü

Preparing Video For Download...