Input:
df = pd.DataFrame({"Month":["Jan","Jan","Jan","Jan","Feb","Feb","Feb","Mar"],
"Week": [1,2,3,4,1,2,3,2],
"Sales":[1000,50,200,300,250,150,100,300]})
Given a sales dataframe, how to get the given op Output:
summary_df = pd.DataFrame({"Month":["Jan","Feb","Mar"],
"Week": [1,1,2],
"Sales":[1000,250,300]})
I have tried the following,
df.groupby(by=['Month']).agg({'Sales':'max'})
and got the output as,
|Month|Sales|
|---|---|
|Feb|250|
|Jan|1000|
|Mar|300|