How to do a boxplot bases in rows values instead of column values

Question:

I have some score data from a game I’m playing with friends, it looks like:

df = pd.DataFrame({'Player' : ['A', 'B', 'C', 'D', 'E'], 
                   'Score1' : [100, 150, 110, 180, 125], 
                   'Score2' : [200, 210, np.nan, 125, 293],
                   'Score3' : [50, 35, 200, 100, 180]})

If I do a df.boxplot() I’ll get a boxplot based on the Score#, that is, based in the scores of the whole community:

enter image description here

Now I want to do a boxplot() for each player, so we can see how they rank against each other. Something like this:

enter image description here

First thing I tried was to do a boxplot of the traspose matrix:

df.T.boxplot()

But I get an error IndexError: list index out of range

I think it has to do with the indexes created in the traspose, so I have been playing with them, but I really don’t know what else to do.

Asked By: luisfer

||

Answers:

tdf = df.set_index('Player').T
tdf.boxplot()
plt.show()

enter image description here

Answered By: mechanical_meat

you need to set the index as player

import pandas as pd
import numpy as np

df = pd.DataFrame({'Player' : ['A', 'B', 'C', 'D', 'E'], 
                   'Score1' : [100, 150, 110, 180, 125], 
                   'Score2' : [200, 210, np.nan, 125, 293],
                   'Score3' : [50, 35, 200, 100, 180]})
df = df.set_index('Player')
print df
df.T.boxplot()

enter image description here

Answered By: plasmon360
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.