gpt4 book ai didi

pandas - Pandas :根据字符串计数创建直方图

转载 作者:行者123 更新时间:2023-12-04 00:02:30 30 4
gpt4 key购买 nike

我需要从包含值“低”,“中”或“高”的数据框列创建直方图。当我尝试执行通常的df.column.hist()时,出现以下错误。

ex3.Severity.value_counts()
Out[85]:
Low 230
Medium 21
High 16
dtype: int64

ex3.Severity.hist()


TypeError Traceback (most recent call last)
<ipython-input-86-7c7023aec2e2> in <module>()
----> 1 ex3.Severity.hist()

C:\Users\C06025A\Anaconda\lib\site-packages\pandas\tools\plotting.py in hist_series(self, by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, **kwds)
2570 values = self.dropna().values
2571
->2572 ax.hist(values, bins=bins, **kwds)
2573 ax.grid(grid)
2574 axes = np.array([ax])

C:\Users\C06025A\Anaconda\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
5620 for xi in x:
5621 if len(xi) > 0:
->5622 xmin = min(xmin, xi.min())
5623 xmax = max(xmax, xi.max())
5624 bin_range = (xmin, xmax)

TypeError: unorderable types: str() < float()

最佳答案

ex3.Severity.value_counts().plot(kind='bar')


是您真正想要的。

当您这样做时:

ex3.Severity.value_counts().hist()


它会以错误的方式绕过轴,即尝试将y轴(计数)划分为bin,然后绘制每个bin中的字符串标签数。

关于pandas - Pandas :根据字符串计数创建直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29525120/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com