Pandas:如何根据行值而不是列值绘制箱线图?
Pandas: How to do a boxplot bases in rows values instead of column values?
我有一些与朋友一起玩的游戏的分数数据,它看起来像:
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.boxplot()
我会得到一个基于 Score# 的箱线图,也就是说,基于整个社区的分数:
现在我想为每个玩家绘制一个 boxplot(),这样我们就可以看到他们之间的排名。像这样:
我尝试的第一件事是绘制转置矩阵的箱线图:
df.T.boxplot()
但是我得到一个错误IndexError: list index out of range
我认为这与在转置中创建的索引有关,所以我一直在玩它们,但我真的不知道还能做什么。
tdf = df.set_index('Player').T
tdf.boxplot()
plt.show()
您需要将索引设置为播放器
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()
我有一些与朋友一起玩的游戏的分数数据,它看起来像:
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.boxplot()
我会得到一个基于 Score# 的箱线图,也就是说,基于整个社区的分数:
现在我想为每个玩家绘制一个 boxplot(),这样我们就可以看到他们之间的排名。像这样:
我尝试的第一件事是绘制转置矩阵的箱线图:
df.T.boxplot()
但是我得到一个错误IndexError: list index out of range
我认为这与在转置中创建的索引有关,所以我一直在玩它们,但我真的不知道还能做什么。
tdf = df.set_index('Player').T
tdf.boxplot()
plt.show()
您需要将索引设置为播放器
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()