lui*_*fer 5 python boxplot pandas
我有一些我和朋友一起玩的游戏的分数数据,它看起来像:
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]})
Run Code Online (Sandbox Code Playgroud)
如果我做一个,df.boxplot()我会得到一个基于 Score# 的箱线图,也就是说,基于整个社区的分数:
现在我想为每个玩家做一个 boxplot() ,这样我们就可以看到他们彼此之间的排名。像这样的东西:
我尝试的第一件事是做一个转置矩阵的箱线图:
df.T.boxplot()
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误 IndexError: list index out of range
我认为这与在 traspose 中创建的索引有关,所以我一直在玩它们,但我真的不知道还能做什么。
您需要将索引设置为玩家
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()
Run Code Online (Sandbox Code Playgroud)