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:
Now I want to do a boxplot() for each player, so we can see how they rank against each other. Something like this:
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.
Horizontal Box plots We can turn the boxplot into a horizontal boxplot by two methods first, we need to switch x and y attributes and pass it to the boxplot( ) method, and the other is to use the orient=”h” option and pass it to the boxplot() method.
Steps. Set the figure size and adjust the padding between and around the subplots. Make a Pandas dataframe, i.e., two-dimensional, size-mutable, potentially heterogeneous tabular data. Make a box and whisker plot, using boxplot() method with width tuple to adjust the box in boxplot.
Creating Box PlotThe matplotlib. pyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. The data values given to the ax. boxplot() method can be a Numpy array or Python list or Tuple of arrays.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With