แนะนำ Polars DataFrame

Introduction to Polars

Liam Brannigan

Data Scientist and Polars Contributor

แนะนำผู้สอน

$$

  • Liam Brannigan, Lead Data Scientist
  • ผู้เชี่ยวชาญด้าน ML และ Data Engineering
  • ผู้มีส่วนร่วมพัฒนา Polars

รูปโปรไฟล์ของผู้สอน

Introduction to Polars

ข้อมูลในรูปแบบตาราง

shape: (49, 8)
| name        | type    | price | bedrooms | doubles | singles | review | beach |
| ---         | ---     | ---   | ---      | ---     | ---     | ---    | ---   |
| str         | str     | i64   | i64      | i64     | i64     | f64    | bool  |
|-------------|---------|-------|----------|---------|---------|--------|-------|
| Waves       | Cottage | 540   | 4        | 1       | 2       | 8.9    | false |
| Seashells   | Cottage | 540   | 4        | 2       | 2       | 8.7    | true  |
| Lake view   | Cottage | 714   | 3        | 1       | 4       | 9.2    | true  |
| Piran View  | null    | 775   | null     | 1       | 3       | 9.6    | false |
| Palma Villa | Cottage | 1772  | 4        | 1       | 2       | 9.6    | true  |
Introduction to Polars

ภาพเปรียบเทียบหมีขั้วโลกเดินในหิมะและแพนด้าในป่า

  • Polars มักเร็วกว่า Pandas → ประมวลผลแบบขนาน
  • lazy mode ของ Polars ช่วยให้คิวรีมีประสิทธิภาพมากขึ้น
Introduction to Polars

โลโก้ Apache Arrow และ Rust

  • Apache Arrow: จัดเก็บข้อมูลตารางในหน่วยความจำ
  • Rust: ภาษาที่เร็วสำหรับการประมวลผลข้อมูล
Introduction to Polars

แผนภาพฐานข้อมูลแสดงการโหลดข้อมูล

  • การโหลดและตรวจสอบข้อมูล
Introduction to Polars

แผนภาพฐานข้อมูลและเฟืองแสดงการแปลงข้อมูล

  • การโหลดและตรวจสอบข้อมูล
  • การแปลงข้อมูลและการเพิ่มประสิทธิภาพ
Introduction to Polars

แผนภาพฐานข้อมูล เฟือง และกราฟแสดงการวิเคราะห์ข้อมูล

  • การโหลดและตรวจสอบข้อมูล
  • การแปลงข้อมูลและการเพิ่มประสิทธิภาพ
  • การวิเคราะห์ข้อมูล
Introduction to Polars

การอ่านไฟล์ CSV

import polars as pl


rentals = pl.read_csv("vacation_rentals.csv")
Introduction to Polars

แถวแรกของ DataFrame

rentals.head(3)

แถวแรกของ rentals DataFrame

Introduction to Polars

แถวแรกของ DataFrame

rentals.head(3)

rentals DataFrame ที่ไฮไลต์ shape ไว้

Introduction to Polars

แถวแรกของ DataFrame

rentals.head(3)

rentals DataFrame ที่ไฮไลต์คอลัมน์แรกไว้

  • dtype: ชนิดของข้อมูลในคอลัมน์
Introduction to Polars

แถวแรกของ DataFrame

rentals.head(3)

rentals DataFrame ที่ไฮไลต์คอลัมน์ rentals ไว้

Introduction to Polars

แถวสุดท้ายของ DataFrame

rentals.tail()
shape: (5, 8)
| name                | type      | price | bedrooms | doubles | singles | review | beach |
| ---                 | ---       | ---   | ---      | ---     | ---     | ---    | ---   |
| str                 | str       | i64   | i64      | i64     | i64     | f64    | bool  |
|---------------------|-----------|-------|----------|---------|---------|--------|-------|
| Hengar Manor House  | Cottage   | 615   | 4        | 1       | 5       | 9.4    | false |
| Tudor Cottage Hayle | Cottage   | 489   | 3        | 2       | 3       | 8.9    | false |
| Tolcarne Apartments | Apartment | 1764  | 3        | 1       | 4       | 9.3    | true  |
| Tolcarne Apartments | Apartment | 1605  | 3        | 1       | 4       | 9.3    | true  |
| Tehidy Holiday Park | Cottage   | 637   | 4        | 2       | 4       | 9.0    | false |
Introduction to Polars

เมทาดาทาของ DataFrame

rentals.shape
(49, 8)
rentals.columns
['name', 'type', 'price', 'bedrooms', 'doubles', 'singles', 'review', 'beach']
Introduction to Polars

Schema ของ DataFrame

rentals.schema
Schema([('name', String),
        ('type', String),
        ('price', Int64),
        ('bedrooms', Int64),
        ('doubles', Int64),
        ('singles', Int64),
        ('review', Float64),
        ('beach', Boolean)])
Introduction to Polars

การตรวจสอบ DataFrame

rentals.glimpse()
Rows: 49
Columns: 8
$ name      <str> 'Waves', 'Seashells', 'Lake view', 'Piran View',...
$ type      <str> 'Cottage', 'Cottage', 'Cottage', None, 'Cottage',...
$ price     <i64> 540, 540, 714, 775, 1772, 934, 1947, 1026, 705, 863
$ bedrooms  <i64> 4, 4, 3, None, 4, 3, 4, 3, 4, 3
$ doubles   <i64> 1, 2, 1, 1, 1, 1, 1, 1, 1, 1
$ singles   <i64> 2, 2, 4, 3, 2, 4, 2, 4, 2, 2
$ review    <f64> 8.9, 8.7, 9.2, 9.6, 9.6, 8.6, 9.6, 8.6, 9.7, 9.1
$ beach    <bool> False, True, True, False, True, True, True, True, True, True
Introduction to Polars

มาฝึกกันเถอะ!

Introduction to Polars

Preparing Video For Download...