Pal*_*ine 2 python dataframe python-3.x python-polars
我正在尝试按文档后面的极坐标数据框进行分组:
import polars as pl
df = pl.DataFrame(
{
"a": ["a", "b", "a", "b", "c"],
"b": [1, 2, 1, 3, 3],
"c": [5, 4, 3, 2, 1],
}
)
df.group_by("a").agg(pl.col("b").sum())
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
AttributeError: 'DataFrame' object has no attribute 'group_by'
Run Code Online (Sandbox Code Playgroud)
检查后我发现了我的极地版本:
pl.__version__
0.17.3
Run Code Online (Sandbox Code Playgroud)
我需要去做:
df.groupby("a").agg(pl.col("b").sum()) # there is no underscore in groupby
#output
shape: (3, 2)
a b
str i64
"a" 2
"c" 3
"b" 5
Run Code Online (Sandbox Code Playgroud)
该文件说:
自版本 0.19.0 起已弃用:此方法已重命名为
DataFrame.group_by().
这是新文件polars version 0.19
| 归档时间: |
|
| 查看次数: |
730 次 |
| 最近记录: |