【发布时间】:2021-02-15 02:23:15
【问题描述】:
我从一个包含我需要分析的信息的 csv 文件中提取了某些数据。把它们做成一个DataFrame。然后根据它们所在的“reg”区域类型对它们进行分组。
datafileR = datafile = pd.read_csv("pixel_data.csv")
datafileR = pd.DataFrame(datafileR)
### Counting the number of each rows based on the "Reg":
datafileR["Reg"].value_counts()
这是我收到的结果: enter image description here
根据数据框中的 Reg 列创建一个名为 region 的组:datafileR:
region = datafileR.groupby(["Reg"])
现在在直方图中绘制它们:
sns.set_theme()
plt.hist(datafileR["Reg"].value_counts(), bins=[70,100,130,160,190],color=["grey"],
histtype='bar', align='mid', orientation='vertical', rwidth=0.85)
这是我收到的图像,但 x 轴上应该有五个类别(中东和北非、非洲(不包括 MENA)、亚洲和太平洋、欧洲和欧亚大陆以及跨区域)。我不确定什么时候出错。同时,如何更改 y 轴上的状态以显示实际数字? enter image description here
【问题讨论】:
标签: dataframe matplotlib histogram