我试图在 python 极坐标中水平连接两个 LazyFrame 并收到错误。这是代码:
import polars as pl
df_h1 = pl.DataFrame({"l1": [1, 2], "l2": [3, 4]}).lazy()
df_h2 = pl.DataFrame({"r1": [5, 6], "r2": [7, 8], "r3": [9, 10]}).lazy()
pl.concat([df_h1, df_h2], how="horizontal")
我收到错误:
ValueError: LazyFrame `how` must be one of {'vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'align'}, got 'horizontal'
该代码适用于极坐标数据帧,即,如果您只是删除上面代码中的 .lazy 方法。文档说它应该适用于 LazyFrames。例如,在 LazyFrames 上进行对角串联似乎对我来说效果很好:
df_h1 = pl.DataFrame({"l1": [1, 2], "l2": [3, 4]}).lazy()
df_h2 = pl.DataFrame({"r1": [5, 6], "r2": [7, 8], "r3": [9, 10]}).lazy()
pl.concat([df_h1, df_h2], how="diagonal")
注意:我有极地版本 0.19.12。
此功能最近才由 此 PR 实现,于 2024 年 1 月 2 日与 Python 版 Polars 0.20.3 一起发布。
使用最新的 Polars 版本,您的代码应该可以工作。