Pandas: How to make box bases in row values ββinstead of column values?
I have some score data from a game I play with friends, it looks like this:
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 df.boxplot()
, I get a box based on the # metric, that is, based on dozens of the entire community:
Now I want to do boxplot () for each player so we can see how they compare to each other. Something like that:
The first thing I tried was to make a rectangular matrix:
df.T.boxplot()
But I am getting the error IndexError: list index out of range
I think it has something to do with the indexes created in traspose, so I played around with them, but I really don't know what else to do.
+3
source to share
2 answers
you need to set the index as a 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()
+3
source to share