How to convert index of a pandas dataframe into a column?

前端 未结 7 673
后悔当初
后悔当初 2020-11-22 08:54

This seems rather obvious, but I can\'t seem to figure out how to convert an index of data frame to a column?

For example:

df=
        gi       ptt_l         


        
7条回答
  •  庸人自扰
    2020-11-22 09:23

    A very simple way of doing this is to use reset_index() method.For a data frame df use the code below:

    df.reset_index(inplace=True)
    

    This way, the index will become a column, and by using inplace as True,this become permanent change.

提交回复
热议问题