英文:
How to change this code to polars ?" TypeError: 'GroupBy' object is not subscriptable"
问题
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_reserve_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 solve this error?
英文:
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?
答案1
得分: 6
你可能是指
polars_researve_tb \
.groupby(["hotel_id", "people_num"]).agg(pl.col('total_price').sum())
我建议将可重现的示例发布在将来。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论