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:

enter image description here

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

Upvotes: 0

Views: 36

Answers (1)

SomeDude
SomeDude

Reputation: 14228

I think you are looking for transform:

df['Sell_price'] = df.groupby(['Date', 'Product_id'])['Sell_price'].transform('max')

Upvotes: 2

Related Questions