使用seaborn
问题描述:
category = df.category_name_column.value_counts()
绘制系列中,我有上述一系列的返回值:使用seaborn
CategoryA,100
CategoryB,200
我想要绘制在X的前5类的名字 - 在y轴
轴和值head = (category.head(5))
sns.barplot(x = head ,y=df.category_name_column.value_counts(), data=df)
它不会在X轴上打印类别的“名称”,而是显示计数。如何打印X中的前5个名字和Y中的值?
答
您可以在系列的index
& values
分别传递给x
& y
在sns.barplot
。与绘图代码变为:
sns.barplot(head.index, head.values)
I am trying to plot the top 5 category names in X
主叫category.head(5)
将从系列category
,其可以比顶部5根据出现的每个类别的次数不同返回第五个值。如果您需要5个最常见的类别,则需要先将该系列分类&,然后致电head(5)
。像这样:
category = df.category_name_column.value_counts()
head = category.sort_values(ascending=False).head(5)
我得到AttributeError:'系列'对象没有属性'值' – sagar
抱歉,这是我的一个错字。它应该是'价值' –
完美。它的工作 – sagar