Polars DataFrame 入門

Polars入門

Liam Brannigan

Data Scientist and Polars Contributor

講師紹介

$$

  • Liam Brannigan、主任データサイエンティスト
  • ML・データエンジニアリングの専門家
  • Polars コントリビューター

講師のプロフィール写真。

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  |
Polars入門

雪原を歩くホッキョクグマと森のパンダの並列画像。

  • Polars は一般に Pandas より高速 → 並列計算
  • Polars の遅延モードでクエリ最適化
Polars入門

Apache Arrow と Rust のロゴ。

  • Apache Arrow: メモリ上に表データを保持
  • Rust: 高速なデータ処理言語
Polars入門

データの読み込みを示すデータベースの概略図。

  • データの読み込みと確認
Polars入門

変換を示すデータベースと歯車の概略図。

  • データの読み込みと確認
  • 変換と最適化
Polars入門

分析を示すデータベース、歯車、チャートの概略図。

  • データの読み込みと確認
  • 変換と最適化
  • データ分析
Polars入門

CSV の読み込み

import polars as pl


rentals = pl.read_csv("vacation_rentals.csv")
Polars入門

DataFrame の先頭行

rentals.head(3)

rentals DataFrame の先頭行。

Polars入門

DataFrame の先頭行

rentals.head(3)

形状を強調した rentals DataFrame。

Polars入門

DataFrame の先頭行

rentals.head(3)

最初の列を強調した rentals DataFrame。

  • dtype: 列のデータ型
Polars入門

DataFrame の先頭行

rentals.head(3)

rentals 列を強調した rentals DataFrame。

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 |
Polars入門

DataFrame のメタデータ

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

DataFrame のスキーマ

rentals.schema
Schema([('name', String),
        ('type', String),
        ('price', Int64),
        ('bedrooms', Int64),
        ('doubles', Int64),
        ('singles', Int64),
        ('review', Float64),
        ('beach', Boolean)])
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
Polars入門

Ayo berlatih!

Polars入門

Preparing Video For Download...