Its the sample input. i wanted to group according to the Year column,and wanted to use value counts on month column, then to sort the ‘month’ column according to the month order.
Year | month |
---|---|
2000 | Oct |
2002 | Jan |
2002 | Mar |
2000 | Oct |
2002 | Mar |
2000 | Jan |
I did this:
df.groupby(['Year'])['month'].value_counts()
i got the following output:
year | month |
---|---|
2000 | Oct 2 |
Jan 1 | |
2002 | Mar 2 |
Jan 1 |
now i need to sort the month in the original month order.what can i do?
i want the following output:
year | month |
---|---|
2000 | Jan 1 |
Oct 2 | |
2002 | Jan 1 |
Mar 2 |
New contributor
shaiha razak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.