Can a table have both frequencies and percentages? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Can a table have both frequencies and percentages? (/thread-24092.html) |
Can a table have both frequencies and percentages? - larryb - Jan-30-2020 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. RE: Can a table have both frequencies and percentages? - Larz60+ - Jan-30-2020 please supply a runnable snippet along with sample input data. RE: Can a table have both frequencies and percentages? - jefsummers - Jan-30-2020 The short answer is yes, you can have both, but you will need to change the way you assemble your dataframe. |