python - SPSS风格的“集群”条形图,使用python和pandas在多列中计数
问题描述
我有一些分类数据
example_data = {'Role':['Teacher', 'Teacher', 'Student', 'Admin', 'Student'],
'Preference': ['Online', 'Blended', 'Blended', 'Face-to-face', 'Face-to-face'],
'Location' : ['City', 'City', 'City', 'Rural', 'Rural']}
df = pd.DataFrame(example_data, columns=['Role','Preference','Location'])
我想制作一个“聚集”条形图,其中的计数df['Role']
和df['Preference']
偏好位于 x 轴上,y 轴是每个偏好的计数,每个条形图按角色聚集。在 SPSS 中,这称为聚集条形图,看起来像
现在这个例子显然来自假数据,我并不担心样式,但我尝试了各种排列,但我仍然遗漏了一些东西groupby()
。value_counts()
任何帮助将非常感激
解决方案
推荐阅读
- angular - Angular Service Worker 每次(软)重新加载(Chrome)时都会获取所有文件
- python - 如何从列表中删除一个元素
- node.js - 如何在 mern 应用上显示错误消息
- javascript - 如何在 JS 中在对象数组中找到两个具有相同键/值但输出的对象具有更高的键/值
- r - 使用 lmLst 和区间函数获得每位患者的截距和斜率(作为重复测量研究中的诊断)
- java - 一个类的多个 bean 实例填充了 application.properties 中的值
- yarnpkg - 无法使用 Yarn 安装 typeorm (Ubuntu 20)
- android - 如何使用 Kotlin 在后台获取 Android 设备的经纬度
- algorithm - 迭代 0..n 范围内数字的随机排列,其中 n 较大
- java - 如果我们在 for 循环之前声明了一个变量,并且我们在 java 的 for 循环语句中声明了同名变量。我们得到错误。为什么?