使用Pandas绘制数据系列直方图

2024-04-20 10:07:34 发布

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

我正在绘制熊猫的系列柱状图,如下所示:

df['Primary Type'].value_counts().plot(kind='bar')

尽管如此,这一系列有25个独特的价值观和情节画许多条。有没有可能将频率较低的棒组在一组中?在

提前谢谢你。在


Tags: dfplotvaluetype绘制bar频率情节
2条回答

您可以使用pd.cut来制作直方图箱-

# Example Dataframe
df = pd.DataFrame({'a' : [25, 22, 22, 21, 45, 20, 1, 1, 1, 1, 2, 3, 4, 4, 4]})

cuts = pd.cut(df['a'], [0, 10, 50])
cuts.value_counts().plot(kind='bar')

enter image description here

您可以通过filtering通过^{}完成:

np.random.seed(100)
df = pd.DataFrame(np.random.randint(20, size=(20,1)), columns=['Primary Type'])
print (df)
    Primary Type
0              8
1              3
2              7
3             15
4             16
5             10
6              2
7              2
8              2
9             14
10             2
11            17
12            16
13            15
14             4
15            11
16            16
17             9
18             2
19            12

^{pr2}$

graph

相关问题 更多 >