Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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_researve_tb \
        .groupby("hotel_id", "people_num")['total_price'] \
        .sum().with_row_count()

But, I got the error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"TypeError: ‘GroupBy’ object is not subscriptable"

How to solove this error?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading