0

How to include the margical descriptives by adding another row of "Total" after the "Yes" row of every feature to the current output? And how do move (ZXCVBNM) to the next line? I tried \n but it doesn't work.

# https://stackoverflow.com/questions/18022845/pandas-index-column-title-or-name
descsumm=(final_df.groupby('Y')
         .describe()
         .unstack()
         .unstack(1)
         .reindex(final_df.columns[1:], level=0)).rename_axis(index=('Numerical features','ABCDEFG (ZXCVBNM)')
                                                              ,axis=1)

# https://note.nkmk.me/en/python-pandas-dataframe-rename/
descsumm.rename(index={'Calories': 'Number of calories','Cholesterol': 'Cholesterol (mg)',0:'No',1:'Yes'},
                columns={'count':'n','mean':'Mean','std':'SD','min':'Min','25%':'Q1','50%':'Median','75%':'Q3','max':'Max'}
                ,inplace=True)

# https://stackoverflow.com/questions/37084812/how-to-remove-decimal-points-in-pandas
descsumm.style.format({
    'n': '{:,.0f}'.format,
    'Mean': '{:,.3f}'.format,
    'SD': '{:,.3f}'.format,
    'Min': '{:,.3f}'.format,
    'Q1': '{:,.3f}'.format,
    'Median': '{:,.3f}'.format,
    'Q3': '{:,.3f}'.format,
    'Max': '{:,.3f}'.format
})

Current output

gracenz
  • 9
  • 2

0 Answers0