Home > other >  Why cannot I have a usual dataframe after using pivot()?
Why cannot I have a usual dataframe after using pivot()?

Time:10-27

Under the variable names, there is an extra row that I do not want in my data set

fdi_autocracy = fdi_autocracy.pivot(index=["Country", "regime", "Year"], 
                                    columns="partner_regime",
                                    values =['FDI_outward', "FDI_inward", "total_fdi"],
                                   ).reset_index()
                 Country   regime  Year   FDI_outward FDI_inward total_fdi
partner_regime                               0.0        0.0       0.0
0                Albania    0.0  1995         NaN        NaN       NaN
1                Albania    0.0  1996         NaN        NaN       NaN
2                Albania    0.0  1997         NaN        NaN       NaN
3                Albania    0.0  1998         NaN        NaN       NaN
4                Albania    0.0  1999         NaN        NaN       NaN

What I want is following:

                 Country   regime  Year   FDI_outward FDI_inward total_fdi
                                       
0                Albania    0.0  1995         NaN        NaN       NaN
1                Albania    0.0  1996         NaN        NaN       NaN
2                Albania    0.0  1997         NaN        NaN       NaN
3                Albania    0.0  1998         NaN        NaN       NaN
4                Albania    0.0  1999         NaN        NaN       NaN

CodePudding user response:

IIUC, you don't need the partner_regime? this removes that title

fdi_autocracy.rename_axis(columns=[None, None])
  • Related