简体   繁体   English

如何为我的数据集创建箱线图? (需要数据转换)

[英]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 个框(对于Code10021200 ):

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 ,并添加参数, byDataFrame.boxplot

fig, ax = plt.subplots(figsize=(10,5))
ds.boxplot(vert=False,column='Measure', by='Code', ax=ax)
plt.subplots_adjust(left=0.25)

G

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从具有权重的数据创建箱线图? - How to create a boxplot from data with weights? 我如何优化我在庞大数据集上的嵌入转换? - How can i optimize my Embedding transformation on a huge dataset? pandas 数据集转换以规范化数据 - pandas dataset transformation to normalize the data 如何从 Python 中的预聚合/分组数据创建箱线图? - How to create a boxplot from pre-aggregated/grouped data in Python? 如何创建一个小的数据集来测试我的CNN? - How to create a small dataset to test my CNN? Pytorch: TypeError 当我调用我的 data_transformation function 时,我在其中定义了我的 train_dataset object - Pytorch : TypeError when I call my data_transformation function inside where I define my train_dataset object 如何在箱线图上添加数据标签? - How to add data labels to boxplot? 如何读取我的 exel 表中的特定数据并从读取的每个数据集创建一个图? (Python) - How can I read specific data in my exel sheet and create a plot from each dataset that is read? (Python) 如何使用箱线图检测和删除数据集中的异常值? - How to detect and remove outliers within a dataset using boxplot? 如何修复绘制箱线图? - How do I fix plotting my boxplot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM