Issue
Having a data frame as below. if product 1 and product 2 are repeating simultaneously then need to choose the smallest price.
expected output:
Solution
Does this work for you :
data = {"Product1": ["A", "A", "B", "B", "D","D"],
"Product2": ["B", "B", "C", "C", "E","F"],
"location": ["GOA","Banlore","GOA","Banlore","Delhi","Delhi"],
"Price":[30,40,20,30,10,15]}
df = pd.DataFrame(data)
df = df.loc[df.groupby(['Product1',"Product2"]).Price.idxmin()]
Answered By - grymlin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.