This is my DATA in dataframe "df":
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 am using the below code which gives me the summary of count 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 the % of row calculation as in excel pivot when you right click the pivot and select "show value as -> % of Row Total" . Since my Document is a non-numeric value i was not able to 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 any one please help me figure out a way to get this result??
i am trying to manipulate the pivot data which will give me the row total,not the data from the dataframe and what i wanted is "% of row total". And also most importantly all my data are non-numeric values...