1

This is the current dataframe:

    PersonID    TestResult
12    1.423000e+03    68270
13    1.423000e+03    68270
17    1.978000e+03    9
18    1.978000e+03    746
24    2.384000e+03    166197
25    2.384000e+03    166197

And this is the kind of result I am looking for;

    PersonID    TestResult
12    1.423000e+03    68270    68270
17    1.978000e+03    9    746

1 Answers1

0

IIUC and you wish to have the values aggregated as a list, because you seem to be interested in keeping both values for each index, then you need to use list as the aggfunc for the pivot_table function:

pd.pivot_table(df,index='PersonID',values='TestResult',aggfunc=list)

Outputs:

                TestResult
PersonID                  
1           [68270, 68270]
2                 [9, 746]
3         [166197, 166197]
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53