python - Pandas - Dataframe.set_index - how to keep the old index column

后端 未结 5 1045
借酒劲吻你
借酒劲吻你 2021-02-05 06:36

I have this Dataframe:

import pandas as pd
df = pd.DataFrame({\'Hugo\' : {\'age\' : 21, \'weight\' : 75},
                   \'Bertram\': {\'age\' :         


        
5条回答
  •  执念已碎
    2021-02-05 07:23

    The below is the most efficient since it appends the new index of age and makes sure its inplace

    df.set_index('age',append=True,inplace=True)
    

提交回复
热议问题