टेक्स्ट डेटा क्लीन करना

Polars के साथ Data Transformation

Liam Brannigan

Data Scientist & Polars Contributor

अपने प्रशिक्षक से मिलिए

$$

$$

  • Liam Brannigan, लीड डेटा साइंटिस्ट
  • ML और डेटा इंजीनियरिंग स्पेशलिस्ट
  • Polars कंट्रीब्यूटर

प्रशिक्षक की प्रोफ़ाइल तस्वीर.

Polars के साथ Data Transformation

ट्रांसफॉर्मेशन इंजन

एनीमेशन

Polars के साथ Data Transformation

क्या यह कोर्स आपके लिए है?

$$

  • Polars DataFrame बनाना

$$

  • Polars expression का उपयोग

$$

  • group-by एग्रीगेशन करना

Introduction to Polars - course page

Polars के साथ Data Transformation

Chapter 1

टेक्स्ट डेटा क्लीनिंग डायग्राम

Polars के साथ Data Transformation

Chapter 2

टाइम सीरीज़ डेटा

Polars के साथ Data Transformation

Chapter 3

DataFrames को मिलाना

Polars के साथ Data Transformation

Chapter 4

कस्टम वर्कफ़्लो और कोरिलेशन

Polars के साथ Data Transformation

हमारा डेटासेट

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 के साथ Data Transformation

रेस्टोरेंट रिकमेंडेशन ऐप

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     |
  • whitespace हटाएँ
  • rating और capacity कॉलम कन्वर्ट करें
  • यूनिक आइडेंटिफायर कॉलम बनाएँ
Polars के साथ Data Transformation

expression से dtype कास्ट करना

ratings.with_columns(

)
Polars के साथ Data Transformation

expression से dtype कास्ट करना

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 के साथ Data Transformation

एक से अधिक कॉलम कास्ट करना

ratings.cast(                      )
Polars के साथ Data Transformation

एक से अधिक कॉलम कास्ट करना

ratings.cast({                    })
Polars के साथ Data Transformation

एक से अधिक कॉलम कास्ट करना

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 के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

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 के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

  • .str.contains()
  • .str.strip_chars()
  • .str.strip_chars_start()
  • .str.to_lowercase()
  • ...
Polars के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

  • .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 के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

  • .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 के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

ratings.with_columns(

)
Polars के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

ratings.with_columns(
    pl.col("business")
)
Polars के साथ Data Transformation

टेक्स्ट डेटा क्लीन करना

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 के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

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 के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

ratings.with_columns(

)
Polars के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

ratings.with_columns(
    pl.concat_str(
)
Polars के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

ratings.with_columns(
    pl.concat_str("business", "location"
)
Polars के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

ratings.with_columns(
    pl.concat_str("business", "location", separator=":")
)
Polars के साथ Data Transformation

टेक्स्ट डेटा जोड़ना

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 के साथ Data Transformation

अभ्यास करते हैं!

Polars के साथ Data Transformation

Preparing Video For Download...