我有一个这样的数据集:
区2
将数据帧堆叠,然后执行groupby
+count
expr = "stack(2, 'Zone 1', `Zone 1`, 'Zone 2', `Zone 2`) as (zone, category)"
result = df.selectExpr(expr).groupBy('category', 'zone').count()
结果
+--------+------+-----+
|category| zone|count|
+--------+------+-----+
| A|Zone 1| 3|
| A|Zone 2| 2|
| B|Zone 2| 3|
| B|Zone 1| 2|
+--------+------+-----+
相关内容
- Python pyspark columns count
- postgresql count distinct by col and sum false and true
- 将 printf 语句移动到变量上的递增/递减下方时"count"奇怪的线程行为
- g=Sheet7上的VBA代码给出错误.单元格(rw,Columns.Count).End(xlToLeft).Colu
- COUNT and GROUP BY several columns
- 如何在MySQL中获取Filled(没有Empty和not Null值的列)columns Count
- Count and Max Columns Group By in LINQ
- LINQ Group By multiple columns and also count
- Count 2 columns Mysql
- DataGridView 中的 ColumnCount 和 Columns.Count 有什么区别
- 这个有什么用:df.columns=['count']?
- 如何昏暗细胞(xx,columns.count)
- r语言 - dplyr::count() multiple columns
- count columns where column1 LIKE %something%
- 将方法"Count of Columns"链接到单个查询生成器
- 使用count(column)作为x.count(columns)mysql
- COUNT() columns by a specific value
- 导出到csv与vb.net, gridview .columns.Count等于0列
- Count columns SQL Server
- MySQL GROUP BY and COUNT over Multiple Columns
最新更新
- 清理脚本(而不是在提供的路径中搜索)总是命中系统根目录或运行它的根文件夹
- 无法加载要从中扩展的配置"airbnb" - gitlab ci
- 我如何将任何方程输入到Python中的标准形式?
- 在Swift中从实时数据库Firebase中获取数据
- Devstack单一接口不能在ubuntu 20.04上工作
- Typescript没有安装
- 函数式语言类型推断混乱
- 使用Python从大文件解析数字数据时提高速度
- 如何从Multipass共享文件夹到主机?
- 从CMD或批处理文件中禁用"Notify me when the clock changes"设置
- 在Dockerfile中设置——net=host ?
- 如何在React中将arrayBuffer转换为JSON
- 是否有可能将html响应转换为json在扑动?
- 快速过滤numpy数组值的方法
- C保存字符串的数组列表
- 需要minio film配置建议
- 如何应用CSS字体大小"relative to what it would be originally"?
- 该应用程序在个人帐户中未绑定脚本时被阻止错误
- 将原始查询转换为django orm
- 如何从出现次数和值的列表中创建一个新列表
- 使用Julia中的Julia Broadcasting根据数组的索引计算数组值
- 在javascript中使用条件更新嵌套数组
- for循环多个条件
- 将第一列中的名称行转换为r中的列
- Nx张量的映射切片
- Dotnet Core Azure功能(隔离进程)如何加载应用程序.每个环境的Json
- Discordjs不发送消息
- 边框在css中不显示
- Python pandas中的深度嵌套JSON规范化
- 如何在JSON模式中从正确的对象中选择特定的字段
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium