Metin verisini temizleme

Polars ile Veri Dönüşümü

Liam Brannigan

Data Scientist & Polars Contributor

Eğitmeninizle tanışın

$$

$$

  • Liam Brannigan, Lead Data Scientist
  • ML ve Veri Mühendisliği Uzmanı
  • Polars katkıcısı

Eğitmenin profil resmi.

Polars ile Veri Dönüşümü

Dönüşüm Motoru

Animasyon

Polars ile Veri Dönüşümü

Bu kurs size uygun mu?

$$

  • Bir Polars DataFrame'i oluşturma

$$

  • Bir Polars ifadesi kullanma

$$

  • Group-by toplulaştırması yapma

Polars'a Giriş - kurs sayfası

Polars ile Veri Dönüşümü

Bölüm 1

Metin verisini temizleme diyagramı

Polars ile Veri Dönüşümü

Bölüm 2

Zaman serisi verisi

Polars ile Veri Dönüşümü

Bölüm 3

DataFrame'leri birleştirme

Polars ile Veri Dönüşümü

Bölüm 4

Özel iş akışları ve korelasyon

Polars ile Veri Dönüşümü

Veri setimizle tanışın

import polars as pl

ratings = pl.read_csv("restaurant_ratings.csv")
shape: (5, 5)
| business         | location     | type       | rating | capacity |
| ---              | ---          | ---        | ---    | ---      |
| str              | str          | str        | f64    | f64      |
|------------------|--------------|------------|--------|----------|
|   7burgers       | Wakey Wakey  | restaurant | 5.0    | 55.0     |
| Bang Bang Burger | Forest Rd.   | restaurant | 4.0    | 55.0     |
| Costa Coffee     | City Point   | café       | 5.0    | 41.0     |
|  Costa Coffee    | The Moorgate | takeaway   | 5.0    | 0.0      |
| The Queens Head  | Denman St.   | bar        | 5.0    | 187.0    |
Polars ile Veri Dönüşümü

Restoran öneri uygulaması

shape: (3, 5)
| business         | location     | type       | rating | capacity |
| ---              | ---          | ---        | ---    | ---      |
| str              | str          | str        | f64    | f64      |
|------------------|--------------|------------|--------|----------|
|   7burgers       | Wakey Wakey  | restaurant | 5.0    | 55.0     |
| Bang Bang Burger | Forest Rd.   | restaurant | 4.0    | 55.0     |
| Costa Coffee     | City Point   | café       | 5.0    | 41.0     |
  • Boşlukları kaldırın
  • rating ve capacity sütunlarını dönüştürün
  • Benzersiz tanımlayıcı sütunu oluşturun
Polars ile Veri Dönüşümü

İfade ile veri tipi dönüştürme (cast)

ratings.with_columns(

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

İfade ile veri tipi dönüştürme (cast)

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

Birden çok sütunu dönüştürme (cast)

ratings.cast(                      )
Polars ile Veri Dönüşümü

Birden çok sütunu dönüştürme (cast)

ratings.cast({                    })
Polars ile Veri Dönüşümü

Birden çok sütunu dönüştürme (cast)

ratings.cast({pl.Float64: pl.Int64})
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   | 5      | 0        |
| The Queens Head  | Denman St.   | bar        | 5      | 187      |
Polars ile Veri Dönüşümü

Metin verisini temizleme

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   | 5      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
Polars ile Veri Dönüşümü

Metin verisini temizleme

  • .str.contains()
  • .str.strip_chars()
  • .str.strip_chars_start()
  • .str.to_lowercase()
  • ...
Polars ile Veri Dönüşümü

Metin verisini temizleme

  • .str.contains()
  • .str.strip_chars()
  • .str.strip_chars_start()
  • .str.to_lowercase()
  • ...
1 https://docs.pola.rs/api/python/stable/reference/expressions/string.html
Polars ile Veri Dönüşümü

Metin verisini temizleme

  • .str.contains()
  • .str.strip_chars()
  • .str.strip_chars_start()
  • .str.to_lowercase()
  • ...
1 https://docs.pola.rs/api/python/stable/reference/expressions/string.html
Polars ile Veri Dönüşümü

Metin verisini temizleme

ratings.with_columns(

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

Metin verisini temizleme

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

Metin verisini temizleme

ratings.with_columns(
    pl.col("business").str.strip_chars_start()
)
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   | 5      | 0        |
| The Queens Head  | Denman St.   | bar        | 5      | 187      |
Polars ile Veri Dönüşümü

Metin verisini birleştirme

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   | 5      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
Polars ile Veri Dönüşümü

Metin verisini birleştirme

ratings.with_columns(

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

Metin verisini birleştirme

ratings.with_columns(
    pl.concat_str(
)
Polars ile Veri Dönüşümü

Metin verisini birleştirme

ratings.with_columns(
    pl.concat_str("business", "location"
)
Polars ile Veri Dönüşümü

Metin verisini birleştirme

ratings.with_columns(
    pl.concat_str("business", "location", separator=":")
)
Polars ile Veri Dönüşümü

Metin verisini birleştirme

ratings.with_columns(
    pl.concat_str("business", "location", separator=":").alias("id")
)
shape: (5, 5)
| business         | location     | type       | ... | id                            |
| ---              | ---          | ---        | --- | ---                           |
| str              | str          | str        | ... | str                           |
|------------------|--------------|------------|-----|-------------------------------|
| 7burgers         | Wakey Wakey  | restaurant | ... | 7burgers:Wakey Wakey          |
| Bang Bang Burger | Forest Rd.   | restaurant | ... | Bang Bang Burger:Forest Rd.   |
| Costa Coffee     | City Point   | café       | ... | Costa Coffee:City Point       |
| Costa Coffee     | The Moorgate | takeaway   | ... | Costa Coffee:The Moorgate     |
| The Queens Head  | Denman St.   | bar        | ... | The Queens Head:Denman St.    |
Polars ile Veri Dönüşümü

Hadi pratik yapalım!

Polars ile Veri Dönüşümü

Preparing Video For Download...