This is my DATA in the "df" dataframe:
Document Name Time
SPS2315511 A 1 HOUR
SPS2315512 B 1 - 2 HOUR
SPS2315513 C 2 - 3 HOUR
SPS2315514 C 1 HOUR
SPS2315515 B 1 HOUR
SPS2315516 A 2 - 3 HOUR
SPS2315517 A 1 - 2 HOUR
I use the code below, which gives me a summary of the counter in the pivot table,
table = pivot_table(df, values=["Document"],
index=["Name"], columns=["Time"],
aggfunc=lambda x: len(x),
margins=True, dropna=True)
but what I want is a% row calculation, as in Excel Pivot, when you right-click on Pivot and select "show value as ->% of the total number of rows". Since my document is not a numeric value, I could not get it.
EXPECTED RESULT:
Count of Document Column Labels
Name 1 HOUR 1 - 2 HOUR 2 - 3 HOUR Grand Total
A 33.33% 33.33% 33.33% 100.00%
B 50.00% 50.00% 0.00% 100.00%
C 50.00% 0.00% 50.00% 100.00%
Grand Total 42.86% 28.57% 28.57% 100.00%
Can someone please help me find a way to get this result?
, , , , , "% ". , ...