绘制分位数,子图

2024-09-28 05:22:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图解决一个关于edx的问题,但我似乎不能正确回答。在

尽管图表显示系统显示“你打电话了吗表演()两次?”在

在输出中还显示了以下内容:

array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f86702755c0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f867020dbe0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f867022c198>],
      dtype=object)

如有任何帮助,我们将不胜感激。谢谢

  • 绘制数据帧。
    • 使用函数清除x轴标签plt.xticks公司(). 在
    • 将第一个参数设置为np.arange公司(莱恩(萨尔)_索引分位数)),的 第二个参数等于sal_分位数.索引,以及关键字 参数旋转=“垂直”。在
    • 展示情节。现在用参数subflots=True调用.plot()方法,在不同的轴上绘制列。也展示这个情节。在

^{pr2}$

基于之前的练习。。。。 数据源:https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv

  1. 绘制工资分位数,第一部分

现在你有兴趣画出几个不同的平均分位数 主要类别的薪水,这样你就可以比较不同的分配 薪水。在本练习中,您将为matplotlib准备数据。在

说明书

列median、p25th和p75th当前被编码为字符串。转换这些 列到数值。然后,将每列的值除以1000,使 最终绘图的比例尺更容易阅读。在

找到每个主要类别的三列中的每一列。把这个保存为sal_quantiles


import pandas as pd

# Convert to numeric and divide by 1000

recent_grads['median'] = pd.to_numeric(recent_grads['median'])/ 1000

recent_grads['p25th'] = pd.to_numeric(recent_grads['p25th'])/ 1000

recent_grads['p75th'] = pd.to_numeric(recent_grads['p75th'])/ 1000



# Select averages by major category

columns = ['median', 'p25th', 'p75th']

sal_quantiles = recent_grads.groupby(['major_category'])['median', 'p25th', 'p75th'].mean()

print(sal_quantiles)

Tags: toobjectmatplotlibpdmedianrecent位数numeric

热门问题