Bir DataFrame’i Alt Kümeleme

Polars'a Giriş

Liam Brannigan

Data Scientist and Polars Contributor

Satır seçme

rentals[0]
shape: (1, 8)
| name      | type    | price | bedrooms | doubles | singles | review | beach |
| ---       | ---     | ---   | ---      | ---     | ---     | ---    | ---   |
| str       | str     | i64   | i64      | i64     | i64     | f64    | bool  |
|-----------|---------|-------|----------|---------|---------|--------|-------|
| Seashells | Cottage | 540   | 4        | 2       | 2       | 8.7    | true  |
Polars'a Giriş

Satır seçme

rentals[-1]
shape: (1, 8)
| name                | type    | price | bedrooms | doubles | singles | review | beach |
| ---                 | ---     | ---   | ---      | ---     | ---     | ---    | ---   |
| str                 | str     | i64   | i64      | i64     | i64     | f64    | bool  |
|---------------------|---------|-------|----------|---------|---------|--------|-------|
| Tehidy Holiday Park | Cottage | 637   | 4        | 2       | 4       | 9.0    | false |
Polars'a Giriş

Satır aralığı seçme

rentals[1:3]
shape: (2, 8)
| name      | type    | price | bedrooms | doubles | singles | review | beach |
| ---       | ---     | ---   | ---      | ---     | ---     | ---    | ---   |
| str       | str     | i64   | i64      | i64     | i64     | f64    | bool  |
|-----------|---------|-------|----------|---------|---------|--------|-------|
| Seashells | Cottage | 540   | 4        | 2       | 2       | 8.7    | true  |
| Lake view | Cottage | 714   | 3        | 1       | 4       | 9.2    | true  |
Polars'a Giriş

Bir DataFrame sütunundan Series oluşturma

rentals["name"]
shape: (2,)
Series: 'name' [str]
[
    "Waves"
    "Seashells"
]
  • [] içinde tek sütun bir Series döndürür
  • Series görselleştirmeler için kullanışlıdır
Polars'a Giriş

Köşeli parantezlerle birden çok sütun seçme

rentals[["name", "price"]]
shape: (5, 2)
| name        | price |
| ---         | ---   |
| str         | i64   |
|-------------|-------|
| Waves       | 540   |
| Seashells   | 540   |
| Lake view   | 714   |
| Piran View  | 775   |
| Palma Villa | 1772  |
Polars'a Giriş

Satır ve sütun seçme

rentals[:3, ["name", "price"]]
shape: (3, 2)
| name      | price |
| ---       | ---   |
| str       | i64   |
|-----------|-------|
| Waves     | 540   |
| Seashells | 540   |
| Lake view | 714   |
Polars'a Giriş

.select() ile sütun alt kümeleme

rentals.select("name", "price")
shape: (3, 2)
| name        | price |
| ---         | ---   |
| str         | i64   |
|-------------|-------|
| Waves       | 540   |
| Seashells   | 540   |
| Lake view   | 714   |
df.select(["name", "price"])
Polars'a Giriş

Köşeli parantez mi select mi?

rentals.select("name","price")
shape: (3, 2)
| name        | price |
| ---         | ---   |
| str         | i64   |
|-------------|-------|
| Waves       | 540   |
| Seashells   | 540   |
| Lake view   | 714   |

.select() iyileştirmelere olanak tanır

rentals[["name","price"]]
shape: (3, 2)
| name        | price |
| ---         | ---   |
| str         | i64   |
|-------------|-------|
| Waves       | 540   |
| Seashells   | 540   |
| Lake view   | 714   |
Polars'a Giriş

Hadi pratik yapalım!

Polars'a Giriş

Preparing Video For Download...