首页 > 其他分享 >pyspark的filter()、distinct()、sortBy() 函数

pyspark的filter()、distinct()、sortBy() 函数

时间:2023-08-13 11:13:04浏览次数:35  
标签:pyspark distinct filter rdd result sortBy


#
#   py_pyspark_test.py
#   py_learn
#
#   Created by Z. Steve on 2023/8/12 17:38.
#


from pyspark import SparkConf, SparkContext

conf = SparkConf().setMaster("local[*]").setAppName("rdd_test")

sc = SparkContext(conf=conf)

# rdd = sc.parallelize([1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 19, 20])

rdd = sc.parallelize((("abc", 1), ("def", 10), ("ghi", 11), ("jklc", 21), ("nmnl", 10), ("abxxxc", 101)))

# # 1. rdd.filter()
# result = rdd.filter(lambda x: x % 2 == 0)
# print(result.collect())

# # 2. rdd.distinct() 去除重复
# r1 = rdd.distinct()
# print(r1.collect())


# 3. sortBy()
result = rdd.sortBy(lambda x: x[1], ascending=False, numPartitions=1)
print(result.collect())

标签:pyspark,distinct,filter,rdd,result,sortBy
From: https://www.cnblogs.com/zxhoo/p/17626276.html

相关文章

  • Extended Kalman Filter vs. Error State Kalman Filter for Aircraft Attitude Estim
    EKF与ESKF的对比“Engineerscansolveexactproblemsusingnumericalapproximations,ortheycansolveapproximateproblemsexactly"-FredDaum.对出现在实际问题中的非线性的运动学(dynamic)模型以及/或非线性的观测方程进行线性化的操作,然后基于这个线性化的方程计算......
  • OpenSessionInViewFilter 的配置及作用
    Spring为我们解决Hibernate的Session的关闭与开启问题。Hibernate允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个HibernateSession范围之内进行。如果Service层返回一个启用了延迟加载功能的领域对象给Web层,当Web层访问到那些需要延迟加载的数据......
  • filter() 函数
     1.  filter()函数    用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象,如果要转换为列表,可以使用list()来转换。该接收两个参数,    第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判断,然后返回True或False,最后将返回True......
  • TypeScript中使用数组的filter方法
    constarr:string[]=['pom','皮蛋编程','非常厉害','太棒了'];constfilteredArr:string[]=arr.filter((str:string)=>{returnstr.includes('编程');});console.log(filteredArr);//["皮蛋编程"] ar......
  • 输入框 input的 支持 clearable 清空 select 下拉列表框的 支持 clearable 清空 fil
    开发的前端 中select 下拉列表框 必须支持1、模糊查询2、清空按钮......
  • 软件测试|MySQL DISTINCT关键字过滤重复数据
    简介在MySQL中,有时候我们需要从表中检索唯一的、不重复的数据。这时,我们可以使用DISTINCT关键字来过滤掉重复的数据行。在本文中,我们将深入探讨MySQL中DISTINCT的用法以及如何在查询中使用它来得到不重复的结果集。基本语法DISTINCT关键字用于在SELECT语句中指示查询结果中去除重复......
  • Antd的filterOption的使用
    <Selectmode="multiple"placeholder="请选择组成辅料"style={{width:'100%'}}optionFilterProp="children"filterOption={(input,......
  • 【Python】PySpark 数据计算 ④ ( RDD#filter 方法 - 过滤 RDD 中的元素 | RDD#distin
    文章目录一、RDD#filter方法1、RDD#filter方法简介2、RDD#filter函数语法3、代码示例-RDD#filter方法示例二、RDD#distinct方法1、RDD#distinct方法简介2、代码示例-RDD#distinct方法示例一、RDD#filter方法1、RDD#filter方法简介RDD#filter方法可以根据指定......
  • pandas之filter
    数据准备importpandasaspdproduct_info={"订单号":["2951110000099262111","2181910000909928191","2194560000121355545","1194560000121311126","1483160000121315483"],"数量":[9......
  • 如何将 dubbo filter 拦截器原理运用到日志拦截器中?
    业务背景我们希望可以在使用日志拦截器时,定义属于自己的拦截器方法。实现的方式有很多种,我们分别来看一下。拓展阅读java注解结合springaop实现自动输出日志java注解结合springaop实现日志traceId唯一标识java注解结合springaop自动输出日志新增拦截器与过滤器......