spark 按照key 分组 然后统计每个key对应的最大、最小、平均值思路——使用groupby,或者reduceby
What you're getting back is an object which allows you to iterate over the results. You can turn the results of groupByKey into a list by calling list() on the values, e.g. example = sc.parallelize([(0, u'D'), (0, u'D'), (1, u'E'), (2, u'F')]) example.groupByKey().collect()
# Gives [(0, <pyspark.resultiterable.ResultIterable object ......] example.groupByKey().map(lambda x : (x[0], list(x[1]))).collect()
# Gives [(0, [u'D', u'D']), (1, [u'E']), (2, [u'F'])] # OR:
example.groupByKey().mapValues(list)
Hey Ron, It was pretty much exactly as Sean had depicted. I just needed to provide
count an anonymous function to tell it which elements to count. Since I
wanted to count them all, the function is simply "true". val grouped = rdd.groupByKey().mapValues { mcs =>
val values = mcs.map(_.foo.toDouble)
val n = values.count(x => true)
val sum = values.sum
val sumSquares = values.map(x => x * x).sum
val stddev = math.sqrt(n * sumSquares - sum * sum) / n
print("stddev: " + stddev)
stddev
} I hope that helps
Just don't. Use reduce by key: lines.map(lambda x: (x[1][0:4], (x[0], float(x[3])))).map(lambda x: (x, x)) \
.reduceByKey(lambda x, y: (
min(x[0], y[0], key=lambda x: x[1]),
max(x[1], y[1], , key=lambda x: x[1])))
spark 按照key 分组 然后统计每个key对应的最大、最小、平均值思路——使用groupby,或者reduceby的更多相关文章
- EF GroupBy 根据key 分组 再把key求和(取决于每条数据中 arr的条数) arr 中有多少条数据 就把多少个key 加起来
List<A> alist = new List<A>{ ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ,b=,c=,d=,e=}, ...
- 分享一个Python脚本--统计redis key类型数据大小分布
概述 今天主要介绍怎么统计redis key类型数据大小分布. 原理:使用redis命令: scan.pipline.type 和 debug object 来得到 redis key 信息. 脚本 ...
- MySQL按日期分组并统计截止当前时间的总数(实例教程)
MySQL按日期分组并统计截止当前时间的总数 建表语句 SET NAMES utf8mb4; ; -- ---------------------------- -- Table structure ...
- Spark学习笔记1——第一个Spark程序:单词数统计
Spark学习笔记1--第一个Spark程序:单词数统计 笔记摘抄自 [美] Holden Karau 等著的<Spark快速大数据分析> 添加依赖 通过 Maven 添加 Spark-c ...
- Specified key was too long; max key length is 767 bytes解决方案
问题描述: 1. 使用spark sql处理数据逻辑,逻辑处理后使用 df.write.mode(saveMode).jdbc(url, tableName, connectionPropertie ...
- spark 例子groupByKey分组计算2
spark 例子groupByKey分组计算2 例子描述: 大概意思为,统计用户使用app的次数排名 原始数据: 000041b232,张三,FC:1A:11:5C:58:34,F8:E7:1E:1E ...
- setValue:forUndefinedKey this class is not key value coding-compliant for the key
下午开发过程中遇到一个错误,结果被的真惨,从上午 11 点查错一直查到下午 2 点才找到错误的原因,真的郁闷的不行. 关于查错这么久,主要的原因是: 1. 自己对 IOS 开发还不熟悉2. 不知道 ...
- 数据库操作提示:Specified key was too long; max key length is 767 bytes
操作重现: 法1:新建连接——>新建数据库——>右键数据库导入脚本——>提示:Specified key was too long; max key length is 767 by ...
- Mysql Specified key was too long; max key length is 767 bytes
今天导入一个数据库时,看到以下报错信息: Specified key was too bytes 直译就是索引键太长,最大为767字节. 查看sql库表文件,发现有一列定义如下: 列 名:cont ...
随机推荐
- 6.10---mybatis的实体---接口---接口映射---主配置文件
- 前端-git思维导图笔记
命令汇总 git config配置本地仓库 常用git config --global user.name.git config --global user.email git config --li ...
- .htaccess的基本用法与介绍
●自定义错误页 .htaccess的一个应用是自定义错误页面,这将使你可以拥有自己的.个性化的错误页面(例如找不到文件时),而不是你的服务商提供的错误页或没有任何页面.这会让你的网站在出错的时候看上去 ...
- python--7、面向对象
什么是面向对象 对象,即抽象的一类事物中的某个具体的个体.这个世界中存在的一切皆为对象,不存在的也能创建出来. 较之面向过程的区别: 编程的复杂度远高于面向过程,不了解面向对象而立即上手基于它设计程序 ...
- 修改withdraw 方法
修改withdraw 方法 练习目标-使用有返回值的方法:在本练习里,将修改withdraw方法以返回一个布尔值来指示交易是否成功. 任务 1. 修改Account类 修改deposit 方法返回tr ...
- 【Oracle】表连接三种方式
表连接的方式有三种分别是:排序合并连接(Sort Merge Join).嵌套循环连接(Nested Loops Join).哈希连接(Hash Join). 1. 排序合并连接(Sort Merge ...
- 使用std::cout不能输出显示
在测试一行函数时,出现std::cout不能输出的情况,找不到原因. 1. 只好从main函数第一行,开始测试,直到发现一个函数 o_Initer.ekf_filter(filter, ...
- antd #upload
import React from 'react' import {Upload, Icon, message,Button } from 'antd' import './index.scss'; ...
- Laravel -- windows apache .htaccess https 路由重写
一: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{SERVER_PORT} !^443 RewriteCond %{RE ...
- struct-计算机学习日志
STRUCT实验目的模拟缓冲区溢出的情况.代码总览#include <stdio.h>#include <stdlib.h>typedef struct { int a[2]; ...