Search code examples
python-3.xnumpypicklesklearn-pandas

How to change the name of columns of a Pandas dataframe when it was saved with "pickle"?


I saved a Pandas DataFrame with "pickle". When I call it it looks like Figure A (that is alright). But when I want to change the name of the columns it looks like Figure B. What am I doing wrong? What are the other ways to change the name of columns?

Figure A

enter image description here

Figure B

enter image description here

import pandas as pd

df = pd.read_pickle('/home/myfile')
df = pd.DataFrame(df, columns=('AWA', 'REM', 'S1', 'S2', 'SWS', 'ALL')) 
df

Solution

  • I have just solved it.

    df = pd.read_pickle('/home/myfile')
    
    df1 = pd.DataFrame(df.values*100)
    df1.index='Feature' + (df1.index+1).astype(str) 
    df1.columns=('AWA', 'REM', 'S1', 'S2', 'SWS', 'ALL')
    
    df1