As you determined, the error comes from duplicates in pairs (x, y) for x in Received and y in Merch Ref .
If you want to copy sum , then
ar.pivot_table(index='Received', columns='Merch Ref', values='acceptance_rate', aggfunc=np.sum)
. The default aggregation function is mean . I.e
ar.pivot_table(index='Received', columns='Merch Ref', values='acceptance_rate')
will rotate the table, and all records with the same (x, y) pair will be aggregated using the np.mean function.
Note. I initially got the same error, but after iterating through the pairs (x, y), I did not find duplicates. It turns out that some of the pairs had the form ( nan , nan ) and were excluded from the iteration process. Thus, for other users trying to debug what they consider to be unique pairs, consider checking nan for pd.isnull or pd.notnull .
source share