[英]How to create a boxplot for my dataset? (data transformation needed)
I have the following pandas DataFrame:我有以下熊猫数据帧:
Measure
Code
1200 55.122
1002 49.166
1002 49.263
1002 59.156
1200 49.353
1200 43.000
I want to create a box plot, so that X axis contains Code
values and Y axis contains Measurement
values as boxes (25th percentile, median, 75th percentile).我想创建一个箱线图,以便 X 轴包含
Code
值,Y 轴包含Measurement
值作为框(第 25 个百分位数、中位数、第 75 个百分位数)。
How can I do it?我该怎么做?
This is what I tried, but it creates only 1 box in a plot instead of 2 boxes (for Code
values 1002
and 1200
):这是我尝试过的,但它在图中只创建了 1 个框,而不是 2 个框(对于
Code
值1002
和1200
):
fig, ax = plt.subplots(figsize=(10,5))
ds.boxplot(vert=False)
plt.subplots_adjust(left=0.25)
plt.show()
Use DataFrame.reset_index
for column from index
and add parameter by
to DataFrame.boxplot
:使用
DataFrame.reset_index
从列index
,并添加参数, by
对DataFrame.boxplot
:
fig, ax = plt.subplots(figsize=(10,5))
ds.boxplot(vert=False,column='Measure', by='Code', ax=ax)
plt.subplots_adjust(left=0.25)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.