DataFrames को जोड़ना

Polars के साथ Data Transformation

Liam Brannigan

Data Scientist & Polars Contributor

Reviews डेटा

shape: (5, 4)
| business         | location    | review | price |
| ---              | ---         | ---    | ---   |
| str              | str         | f64    | i64   |
|------------------|-------------|--------|-------|
| 7burgers         | Wakey Wakey | 4.2    | 15    |
| Bang Bang Burger | Forest Rd.  | 3.8    | 12    |
| Costa Coffee     | City Point  | 4.5    | 8     |
| Costa Coffee     | Waterloo    | 4.1    | 8     |
| The Queens Head  | Denman St.  | 4.7    | 25    |
Polars के साथ Data Transformation

Inspections डेटासेट

inspections = pl.read_csv("restaurant_inspections.csv")
shape: (5, 4)
| business        | location    | type       | hygiene_rating |
| ---             | ---         | ---        | ---            |
| str             | str         | str        | i64            |
|-----------------|-------------|------------|----------------|
| 7burgers        | Wakey Wakey | restaurant | 4              |
| Costa Coffee    | City Point  | café       | 5              |
| Costa Coffee    | Waterloo    | café       | 3              |
| The Queens Head | Denman St.  | bar        | 5              |
| Wagamama        | Soho        | restaurant | 4              |
Polars के साथ Data Transformation

Join क्या है?

एकल DataFrame दिखाता डायग्राम.

Polars के साथ Data Transformation

Join क्या है?

दो DataFrames दिखाता डायग्राम.

Polars के साथ Data Transformation

Join क्या है?

मेल खाते key को हाइलाइट किए दो DataFrames का डायग्राम.

Polars के साथ Data Transformation

Join क्या है?

साझा कॉलम पर मिलते rows के आधार पर दो DataFrames को जोड़ते हुए डायग्राम.

Polars के साथ Data Transformation

Join क्या है?

साझा कॉलम पर मिलते rows से जुड़े दो DataFrames, मेल खाते key को हाइलाइट के साथ.

Polars के साथ Data Transformation

एक कॉलम पर join

reviews.join(                                       )
Polars के साथ Data Transformation

एक कॉलम पर join

reviews.join(inspections,                           )
Polars के साथ Data Transformation

एक कॉलम पर join

reviews.join(inspections, on="business"             )
Polars के साथ Data Transformation

एक कॉलम पर join

reviews.join(inspections, on="business", how="inner")
shape: (6, 7)
| business      | location    | ... | location_right | hygiene_rating |
| ---           | ---         | ... | ---            | ---            |
| str           | str         | ... | str            | i64            |
|---------------|-------------|-----|----------------|----------------|
| 7burgers      | Wakey Wakey | ... | Wakey Wakey    | 4              |
| Costa Coffee  | City Point  | ... | City Point     | 5              |
| Costa Coffee  | Waterloo    | ... | City Point     | 5              |
| Costa Coffee  | City Point  | ... | Waterloo       | 3              |
| Costa Coffee  | Waterloo    | ... | Waterloo       | 3              |
| The Queens Hd | Denman St.  | ... | Denman St.     | 5              |
Polars के साथ Data Transformation

एकाधिक कॉलम पर join

reviews.join(inspections, on=["business", "location"])
Polars के साथ Data Transformation

एकाधिक कॉलम पर join

reviews.join(inspections, on=["business", "location"])
shape: (4, 6)
| business        | location    | review | price | type       | hygiene_rating |
| ---             | ---         | ---    | ---   | ---        | ---            |
| str             | str         | f64    | i64   | str        | i64            |
|-----------------|-------------|--------|-------|------------|----------------|
| 7burgers        | Wakey Wakey | 4.2    | 15    | restaurant | 4              |
| Costa Coffee    | City Point  | 4.5    | 8     | café       | 5              |
| Costa Coffee    | Waterloo    | 4.1    | 8     | café       | 3              |
| The Queens Head | Denman St.  | 4.7    | 25    | bar        | 5              |
Polars के साथ Data Transformation

Left join

reviews.join(inspections, on=["business", "location"],           )
Polars के साथ Data Transformation

Left join

reviews.join(inspections, on=["business", "location"], how="left")
shape: (5, 6)
| business         | location    | review | price | type       | hygiene_rating |
| ---              | ---         | ---    | ---   | ---        | ---            |
| str              | str         | f64    | i64   | str        | i64            |
|------------------|-------------|--------|-------|------------|----------------|
| 7burgers         | Wakey Wakey | 4.2    | 15    | restaurant | 4              |
| Bang Bang Burger | Forest Rd.  | 3.8    | 12    | null       | null           |
| Costa Coffee     | City Point  | 4.5    | 8     | café       | 5              |
| Costa Coffee     | Waterloo    | 4.1    | 8     | café       | 3              |
| The Queens Head  | Denman St.  | 4.7    | 25    | bar        | 5              |
Polars के साथ Data Transformation

Full join

reviews.join(inspections, on=["business", "location"],                          )
Polars के साथ Data Transformation

Full join

reviews.join(inspections, on=["business", "location"], how="full"               )
Polars के साथ Data Transformation

Full join

reviews.join(inspections, on=["business", "location"], how="full", coalesce=True)
shape: (6, 6)
| business         | location    | review | price | type       | hygiene_rating |
| ---              | ---         | ---    | ---   | ---        | ---            |
| str              | str         | f64    | i64   | str        | i64            |
|------------------|-------------|--------|-------|------------|----------------|
| 7burgers         | Wakey Wakey | 4.2    | 15    | restaurant | 4              |
| Costa Coffee     | City Point  | 4.5    | 8     | café       | 5              |
| Costa Coffee     | Waterloo    | 4.1    | 8     | café       | 3              |
| The Queens Head  | Denman St.  | 4.7    | 25    | bar        | 5              |
| Wagamama         | Soho        | null   | null  | restaurant | 4              |
| Bang Bang Burger | Forest Rd.  | 3.8    | 12    | null       | null           |
Polars के साथ Data Transformation

Join रणनीति कैसे चुनें

2 टेबल

Polars के साथ Data Transformation

Inner join

Inner join का निरूपण

Polars के साथ Data Transformation

Left join

Left join का निरूपण

Polars के साथ Data Transformation

Full join

Full join का निरूपण

Polars के साथ Data Transformation

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

Polars के साथ Data Transformation

Preparing Video For Download...