0

There's a dataset that has yearly data in string format as -

Year                Products bought
FY 2021-11 (Nov)          100
FY 2022-03 (Mar)          520
FY 2021-10 (Oct)          250
FY 2022-12 (Dec)          400
 .....                   .....
FY 2022-01 (Jan)          800

I want to set the month column based on orderly year and month. I have performed df.sort['Year'] but gives result in different order. How can I set it in form of -

Year               Products bought
FY 2021-10 (Oct)          250
FY 2021-11 (Nov)          100
FY 2022-03 (Mar)          520
FY 2022-01 (Jan)          800
 .....                   .....
FY 2022-12 (Dec)          400     
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
jiah
  • 11
  • 3
  • What version of pandas are you using? `df.sort()` has been deprecated and replaced by `df.sort_values()` – Pranav Hosangadi Mar 29 '22 at 15:09
  • Does this answer your question? [how to sort pandas dataframe from one column](https://stackoverflow.com/questions/37787698/how-to-sort-pandas-dataframe-from-one-column) – Pranav Hosangadi Mar 29 '22 at 15:09
  • @PranavHosangadi pandas version is 1.3.3 – jiah Mar 29 '22 at 15:10
  • Please provide a [mre] and show the output you actually get. When I run `df.sort_values('Year')` on the dataframe you provide, I get the expected output: https://i.stack.imgur.com/aZKHF.png – Pranav Hosangadi Mar 29 '22 at 15:12
  • In my case, the output comes as per ascending order of products brought – jiah Mar 29 '22 at 15:17

0 Answers0