Search code examples
pythonpandasdataframeheader

Remove header index in pandas Dataframe


I have the following dataframe :


                            0                        1         2    ... 630 631 632
0                         index                MATRICULE    ID_UEV  ...            
1       9936-25-3989-4-000-0000  9936-25-3989-4-000-0000  01045406  ...            
2       9739-83-9737-8-001-0302  9739-83-9737-8-001-0302  01038232  ...            
3       9754-37-9664-9-000-0000  9754-37-9664-9-000-0000  02004842  ...            
4       8134-96-8810-1-000-0000  8134-96-8810-1-000-0000  04007065  ...  

How can I remove the first row/index so I can have index MATRICULE, ID_UEV as a header


0                         index                MATRICULE    ID_UEV  ...            
1       9936-25-3989-4-000-0000  9936-25-3989-4-000-0000  01045406  ...            
2       9739-83-9737-8-001-0302  9739-83-9737-8-001-0302  01038232  ...            
3       9754-37-9664-9-000-0000  9754-37-9664-9-000-0000  02004842  ...            
4       8134-96-8810-1-000-0000  8134-96-8810-1-000-0000  04007065  ...  

Solution

  • You can use

    df.columns = df.loc[0]
    df = df.drop(0)
    

    This sets the columns to the items in the first row, then drops the first row.