pythonsparkfilter_过滤RDD基于条件并在Spark python中提取匹配的数据

我有这样的数据,

cl_id cn_id cn_value

10004, 77173296 ,390.0

10004, 77173299 ,376.0

10004, 77173300 ,0.0

20005, 77173296 ,0.0

20005, 77173299 ,6.0

2005, 77438800 ,2.0

Cl_id ID:10004,20005

按10004过滤

10004, 77173296 ,390.0

10004, 77173299 ,376.0

按20005过滤

20005, 77173296 ,0.0

20005, 77173299 ,6.0

现在我想要返回RDD之类的,

10004,cn_id,x1(77173296.value,77173300.value) ==> 10004,77173296,390.0,376.0

20005,cn_id,x1(77173296.value,77173300.value) ==> 20005,77173296,0.0,6.0

我想对这个return_RDD执行一些操作:

def cal_for(rdd_list):

#list.map(position1).filter(cn_id for this formula)-> calculate that formula -> store in a separate RDD -> Return that RDD

rdd_list = rdd_list.map(lambda line:line.split(','))

new_list = rdd_list.map(lambda x: (x[0]+', '+x[1],float(x[2])))

new_list = rdd_list.filter(lambda x: x[1] == '77173296' && x[1] == '77173299')

## then get the RDD containing respective cn_values for cn_id 77173296 & cn_id 77173299

## and apply the following formula whre a=77173296.value b=77173299.value for cl_id 1004

try:

# want to process RDD with this Formula

return ((float(a)/float(a+b))*100)

except ZeroDivisionError:

return 0

#return or save cal_RDD

不是过滤RDD两次,修改和重新组合生成的RDD,只需按id分组,然后映射值以进行所需的任何更改.如果要根据某些条件进一步限制结果,请在映射时执行过滤.

我真的不能给你一个更准确的答案:

a)看起来你还没有真正尝试过这个,而且b)我不完全确定你想要什么.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值