如何解决如何用lambda函数为pyspark数据帧编写reduce? 解决方案
我想用lambda实现reduce函数。例如,如果有pyspark数据帧并且在某列上,我想获取这些列值长度在某个范围之间的所有记录。如何使用带有lambda的reduce函数来实现。 我试图用下面的代码实现它,但是对此我不太确定。
WHERE description SIMILAR TO '%[0-9]{2,3}%'
bad_df = reduce(lambda x,(min < f.col(x) < max for x in df.columns if x in col_list))
包含要检查其列值是否在范围内的列的列表。
解决方法
通过问题和方法,我了解到您想验证col_list
中的所有列是否都在(min,max)
内。
解决方案
total = df.count
ans = True
for col_name in col_list:
#check if all values of that column lie within the range
match_count = df.where(min < col(col_name) < max).count
ans = count == match_count
#if not then no need to go further
if not ans:
break
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。