我根据员工的“性别”和“教育背景”计算了公司的员工总数。现在我想以条形图的形式将其可视化,但我已经尝试过了,但仍然无法直观地查看它
代码:
df1 = pd.pivot_table(comp2, index = ['Gender', 'EducationBackground'], aggfunc={'EducationBackground':'count'})
结果:
"""
EducationBackground
Gender EducationBackground
Female Life Sciences 30
Marketing 15
Medical 21
Other 2
Technical Degree 7
Male Human Resources 3
Life Sciences 48
Marketing 14
Medical 42
Other 1
Technical Degree 11
想象:
sns.countplot(df1,hue='EducationBackground')
错误:
Could not interpret input 'EducationBackground'
sns.countplot
已经执行了聚合(类似于您在pivot_table
中所做的操作),因此您可能可以通过直接在comp2
数据帧上使用sns.countplot
来获得所需的内容,例如:注意:在
df1
上使用sns.barplot
可以获得类似的结果相关问题 更多 >
编程相关推荐