How to sort pandas dataframe by custom order on string index

前端 未结 3 2056
北恋
北恋 2020-12-15 22:32

I have the following data frame:

import pandas as pd

# Create DataFrame
df = pd.DataFrame(
{\'id\':[2967, 5335, 13950, 6141, 6169],\\
 \'Player\': [\'Cedric         


        
3条回答
  •  隐瞒了意图╮
    2020-12-15 22:54

    Just reindex

    df.reindex(reorderlist)
    Out[89]: 
                     Age   G   Tm  Year     id
    Player                                    
    Maurice Baker     25   7  VAN  2004   5335
    Adrian Caldwell   31  81  DAL  1997   6169
    Ratko Varda       22  60  TOT  2001  13950
    Ryan Bowen        34  52  OKC  2009   6141
    Cedric Hunter     27   6  CHH  1991   2967
    

提交回复
热议问题