5

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 image

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

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.