Python Forum
Can a table have both frequencies and percentages?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can a table have both frequencies and percentages?
#1
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.
Reply
#2
please supply a runnable snippet along with sample input data.
Reply
#3
The short answer is yes, you can have both, but you will need to change the way you assemble your dataframe.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020