It's not a mistake. That is how it should work.
The DataFrame should show every single element in it. Therefore, if the index has one level, this level will be fully expanded. If it has two levels, the first level will be grouped, and the second will be fully expanded, if it has tree levels, the first two will be grouped, and the third will be expanded, etc.
That is why the name of the horse is not grouped. How would you see all the elements in a DataFrame if you also group the horse name :)
Try to do:
rdata.set_index(['race_date', 'track_code', 'race_number'])
or
rdata.set_index(['race_date', 'track_code'])
You will see that the last level of the index always expands completely so that you can see all the elements in the DataFrame.
Viktor Kerkez
source share