I am trying to group by a polars dataframe following the document:
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())
However, I am getting this error:
AttributeError: 'DataFrame' object has no attribute 'group_by'
On checking I found my polars version :
pl.__version__
0.17.3
I need to do:
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
and the document says :
Deprecated since version 0.19.0: This method has been renamed to
DataFrame.group_by()
.
This is the new document for polars version 0.19