How to change this code to polars ?" TypeError: 'GroupBy' object is not subscriptable"
Question:
This code is pandas.
pandas_reserve_tb
.groupby(['hotel_id', 'people_num'])['total_price']
.sum().reset_index()
I would like to change this code to polars.
polars_researve_tb
.groupby("hotel_id", "people_num")['total_price']
.sum().with_row_count()
But, I got the error
"TypeError: ‘GroupBy’ object is not subscriptable"
How to solove this error?
Answers:
You probably meant
polars_researve_tb
.groupby(["hotel_id", "people_num"]).agg(pl.col('total_price').sum())
I’d advise posting reproducible examples in the future
This code is pandas.
pandas_reserve_tb
.groupby(['hotel_id', 'people_num'])['total_price']
.sum().reset_index()
I would like to change this code to polars.
polars_researve_tb
.groupby("hotel_id", "people_num")['total_price']
.sum().with_row_count()
But, I got the error
"TypeError: ‘GroupBy’ object is not subscriptable"
How to solove this error?
You probably meant
polars_researve_tb
.groupby(["hotel_id", "people_num"]).agg(pl.col('total_price').sum())
I’d advise posting reproducible examples in the future