I have a Series object that has:
date price dec 12 may 15 apr 13 ..
Problem:. I want it to be displayed by month and calculate the average price for each month and present it in a sorted way by month.
Output Required:
month mean_price Jan XXX Feb XXX Mar XXX
I thought to create a list and pass it in sorting:
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
but sort_values ββdoes not support this for rows.
I have one big problem: even if
df = df.sort_values(by='date',ascending=True,inplace=True) works to the initial df , but after I did groupby , it did not maintain the order coming out of the sorted df .
In conclusion, I needed these two columns from the source data. The datetime column is sorted and through the group using the month (dt.strftime ('% B')) the sorting is messed up. Now I need to sort it by the name of the month.
My code is:
df
source share