I have a pandas dataframe (df) and I need to sort it based on the counts of the values of a column. The values of the column are string.
For example, the target column's values are orange, apple, banana, peach. The individual counts ( df['fruit'].value_counts() ) are:
- banana 2678
- peach 2250
- orange 1765
- apple 1691
The result I need the initial dataframe (with all the columns etc) sorted based on these counts. So, in the first 2678 rows the value in the fruit column should be banana etc