कंडीशनल expressions बनाना

Polars के साथ Data Transformation

Liam Brannigan

Data Scientist & Polars Contributor

रेटिंग क्वालिटी के आधार पर वर्गीकरण

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      |
  • कार्य: हाई-रेटेड restaurants पहचानें
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(


)
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(                     )

)
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

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

)
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Highly Rated"))

)

$$

$$

  • pl.lit() का उपयोग literal वैल्यू पास करने के लिए करें, कॉलम नाम नहीं
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Highly Rated"))
    .otherwise(pl.lit("Needs Improvement"))
)
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Highly Rated"))
    .otherwise(pl.lit("Needs Improvement")).alias("quality")
)
Polars के साथ Data Transformation

रेटिंग क्वालिटी के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("rating") == 5).then(pl.lit("Highly Rated"))
    .otherwise(pl.lit("Needs Improvement")).alias("quality")
)
shape: (5, 6)
| business         | location        | type       | rating | capacity | quality            |
| ---              | ---             | ---        | ---    | ---      | ---                |
| str              | str             | str        | i64    | i64      | str                |
|------------------|-----------------|------------|--------|----------|--------------------|
| 7burgers         | Wakey Wakey     | restaurant | 5      | 55       | Highly Rated       |
| Bang Bang Burger | Forest Rd.      | restaurant | 4      | 55       | Needs Improvement  |
| ...              | ...             | ...        | ...    | ...      | ...                |
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   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
  • कार्य: capacity के आधार पर restaurants फ़िल्टर करें
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

ratings.with_columns(



)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

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


)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

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


)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Large"))
    .when(pl.col("capacity") >= 20)

)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Large"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Medium"))

)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Large"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Medium"))
    .otherwise(pl.lit("Small"))
)
Polars के साथ Data Transformation

वेन्यू साइज़ के आधार पर वर्गीकरण

ratings.with_columns(
    pl.when(pl.col("capacity") > 100).then(pl.lit("Large"))
    .when(pl.col("capacity") >= 20).then(pl.lit("Medium"))
    .otherwise(pl.lit("Small")).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       | Medium     |
| Costa Coffee     | The Moorgate    | takeaway   | 3      | 0        | Small      |
| The Queens Head  | Denman St.      | bar        | 5      | 187      | Large      |
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   | 3      | 0        |
| The Queens Head  | Denman St.      | bar        | 5      | 187      |
  • कार्य: type कॉलम स्टैंडर्डाइज़ करें
Polars के साथ Data Transformation

बिज़नेस टाइप्स का स्टैंडर्डाइज़ेशन

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

बिज़नेस टाइप्स का स्टैंडर्डाइज़ेशन

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

बिज़नेस टाइप्स का स्टैंडर्डाइज़ेशन

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

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

Polars के साथ Data Transformation

Preparing Video For Download...