🐷
Polarsのスキーマ定義で使えるデータ型一覧
はじめに
pandas(スター数:45.2K)に変わり人気を博しているpolars(スター数:33.2K)ですが、読み込み時にschemaを定義できたりします。
その際に使用できるデータ型を以下にまとめています。
Polars データ型一覧:定義、例、およびJSONスキーマでの指定方法
カテゴリ | データ型 | 説明 | 具体例 | JSONでの指定 |
---|---|---|---|---|
整数型 | Int8 | 8ビット符号付き整数 | -128 ~ 127 | "age": "Int8" |
Int16 | 16ビット符号付き整数 | -32,768 ~ 32,767 | "year": "Int16" | |
Int32 | 32ビット符号付き整数 | -2,147,483,648 ~ 2,147,483,647 | "population": "Int32" | |
Int64 | 64ビット符号付き整数 | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 | "big_number": "Int64" | |
UInt8 | 8ビット符号なし整数 | 0 ~ 255 | "small_count": "UInt8" | |
UInt16 | 16ビット符号なし整数 | 0 ~ 65,535 | "medium_count": "UInt16" | |
UInt32 | 32ビット符号なし整数 | 0 ~ 4,294,967,295 | "large_count": "UInt32" | |
UInt64 | 64ビット符号なし整数 | 0 ~ 18,446,744,073,709,551,615 | "very_large_count": "UInt64" | |
浮動小数点型 | Float32 | 32ビット浮動小数点数 | 3.14159 | "price": "Float32" |
Float64 | 64ビット浮動小数点数 | 3.141592653589793 | "precise_measurement": "Float64" | |
文字列型 | Utf8 | UTF-8エンコードされた文字列 | "Hello, 世界!" | "name": "Utf8" |
ブール型 | Boolean | 真偽値 | true, false | "is_active": "Boolean" |
日付・時間型 | Date | 日付 | 2023-05-17 | "birth_date": "Date" |
Datetime | 日付と時刻 | 2023-05-17 15:30:00 | "created_at": "Datetime" | |
Time | 時刻 | 15:30:00 | "start_time": "Time" | |
Duration | 期間 | 1 day 2 hours 30 minutes | "elapsed_time": "Duration" | |
複合型 | List | リスト(配列) | [1, 2, 3, 4, 5] | "scores": "List(Int64)" |
["red", "green", "blue"] | "colors": "List(Utf8)" | |||
[[1, 2], [3, 4]] | "matrix": "List(List(Int64))" | |||
Struct | 構造体 | {"name": "John", "age": 30} | "user_info": "Struct([('name', 'Utf8'), ('age', 'UInt8')])" | |
{"coords": {"x": 1.0, "y": 2.0}} | "point": "Struct([('coords', Struct([('x', 'Float64'), ('y', 'Float64')]))])" | |||
その他 | Null | 欠損値 | null | "optional_field": "Null" |
Categorical | カテゴリデータ | "Red", "Green", "Blue" | "color": "Categorical" | |
Object | Pythonオブジェクト(非推奨) | Any Python object | "custom_object": "Object" |
json file exp
{
"id": "UInt32",
"name": "Utf8",
"age": "UInt8",
"salary": "Float32",
"hire_date": "Date",
"is_manager": "Boolean",
"department": "Categorical",
"performance_scores": "List(Float64)",
"contact_info": "Struct([('email', 'Utf8'), ('phone', 'Utf8')])",
"projects": "List(Struct([('name', 'Utf8'), ('status', 'Categorical')]))"
}
Discussion