Python Forum

Full Version: Can a table have both frequencies and percentages?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So my normal method for creating a table produces EITHER frequencies OR percentages.
I would really like to produce both frequencies AND percentages in the same table.

My code for the frequency tables is:
tab001 = pd.crosstab(data[my_list[13]].\
    map(meta.variable_value_labels[my_list[13]]), \
    data['qdp2'].map(meta.variable_value_labels['qdp2']), \
    dropna=True, margins=True). \
    loc[meta.variable_value_labels[my_list[13]].values()]. \
    loc[:,meta.variable_value_labels['qdp2'].values()].round(4)
To produce percentages i use the same code but add:
, normalize= 'columns'
Any help with getting frequencies and percentages in the same table would be appreciated.
please supply a runnable snippet along with sample input data.
The short answer is yes, you can have both, but you will need to change the way you assemble your dataframe.