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?

Asked By: assa

||

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

Answered By: ignoring_gravity
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.