I have a dataframe that I sorted by the datetime index. Since there are many entries for each date, I would like it to further sort by the column "Ticker" alphabetically within each date. How do you do this? Image of dataframe attached
1 Answer
You can try reset_index()+sort_values()+set_index():
so the idea is to reset the current index then sort 'Date' along with 'Ticker' then after sorting set 'Date' as index
df=df.reset_index().sort_values(['Date','Ticker']).set_index('Date')
1 Comment
sammywemmy
try
df.sort_values(['Date','Ticker']), since the index has a name, it should work (at least with Pandas 1.1)