Reputation: 73
I created a dataframe from a list of dataframes like this:
team_df = pd.concat(all_teams, keys=flat_list, axis=0)
I attached a picture of the output.
I want to convert
it to is something like this:
team1
player 1
player 2
player 3
player 4
player 5
player 6
team2
player 1
player 2
player 3
player 4
player 5
player 6
Upvotes: 5
Views: 3128
Reputation: 76917
You can use pd.MultiIndex.from_tuples
to set index.
In [1045]: df.index = pd.MultiIndex.from_tuples(df.index, names=['team', 'player'])
In [1046]: df
Out[1046]:
d
team player
1 2 1
3 2
2 3 3
Upvotes: 7