我对Pypark很陌生。我希望我能在这里得到答案。我需要一个使用DataFrameAPI的答案
我的问题是查找文本文件test.txt中包含单词“testA”或“testB”或“testC”的行数
lines=spark.read.text("C:\test.txt")
listStr=["testA","testB","testC"]
lines.filter(lines.isin(listStr)).count() --> this is showing all the lines in the textfile
附言:如果可以用“lambda”来解决,那就更好了
要从列表中查找包含一个字符串的所有行,可以使用方法^{} 。例如:
输出:
您的解决方案不起作用,因为方法^{} 测试单元格值是否等于列表中的一个值。您只能对列对象(在PySpark 3中)使用此方法,否则将得到
AttributeError
。它将适用于以下数据帧:输出:
您还可以使用
like
:如果要使用lambda函数,可以使用RDD:
相关问题 更多 >
编程相关推荐