How can I groupby a column (match_id) and reshape the dataframe to wide format, naming new created columns based on the number of column (player) items, starting from:
match_id player goals home
1 John 1 home
1 Jim 3 home
...
2 John 0 away
2 Jim 2 away
...
and reshaping it to:
match_id player_1 player_2 player_1_goals player_2_goals player_1_home player_2_home ...
1 John Jim 1 3 home home
2 John Jim 0 2 away away
...
for a 'n' (1, 2, 3, 4...) number of players?
This is not simply a matter of pivoting the dataframe but also properly dinamically renaming the columns.