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 can I apply the results of groupby command to all rows?

I have a dataframe as follows:

enter image description here

I want to have the max of the ‘Sell_price’ column according to ‘Date’ and ‘Product_id’ columns, without losting the dimension of dataframe as:

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

enter image description here

Since my data is very big, without a doubt using ‘for’ command is not logical.

Thanks for your time and consideration.

>Solution :

I think you are looking for transform:

df['Sell_price'] = df.groupby(['Date', 'Product_id'])['Sell_price'].transform('max')
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