Polars
文章目录
教程
官方 Get Started
polar expression
polar.all() vs. Expr.all() 两者作用不同
- polar.all(): 选择所有列
- Expr.all(): expression 的一个方法,逻辑判断全为 true, 类似 python 内建函数 all
polar.flatten() 类似 pd.Series.explode()
作用:
- 拆分单元格中的列表元素到不同的新行
polar namespace 概念
类别:
- str: string
- dt: datetime
arr: array
window function
pl.read_csv()
dtype 错误
解决办法:
- 手动指定:
dtypes={'a_col': pl.Int64, ...} 调整
infer_schema_length = num一个较大的数值- 多次调整 num, 直到成功位置
设定推断类似涉及的行数为 0:
pl.read_csv(..., infer_schema_length=0)- 设 infer_schema_length=0, pl.read_csv 把所有列读取成 pl.Utf8
- 读取完成后再手动调整类型
eg:
1 2 3 4 5 6 7 8 9 10import polars as pl (pl.read_csv("test.csv", infer_schema_length=0) .with_columns( [ pl.select('a').cast(pl.Uint8, strict=True) ] )
filter
过滤条件连接使用 "&"
| |
文章作者
上次更新 2023-02-01 (9aed3e4)