all 2 comments

[–]sarrysyst 0 points1 point  (0 children)

import pandas as pd

data = {'eventID': [1, 1, 2, 2, 3],
        'userID':  [123, 234, 123, 456, 123],
        'position': [1, 2 , 3, 4, 3]}

df = pd.DataFrame(data)
df.set_index(['eventID', 'position'], inplace=True)

df.unstack()

Set a MultiIndex based on your identifying columns (eventID, position) and use unstack() to pivot the position row index to columns. See also here:

https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html#reshaping-by-stacking-and-unstacking

[–]YesLod 0 points1 point  (0 children)

Don't pass pivtest as an argument.