Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pyspark-数据帧中的动态where子句_Pyspark - Fatal编程技术网

Pyspark-数据帧中的动态where子句

Pyspark-数据帧中的动态where子句,pyspark,Pyspark,是否可以在数据帧中执行动态“where/filter”? 我正在运行“like”操作来删除与特定字符串匹配的项 eventsDF.where( ~eventsDF.myColumn.like('FirstString%') & ~eventsDF.myColumn.like('anotherString%') ).count() 但是,我需要根据来自另一个数据帧/列表的字符串进行筛选 我想要的解决方案(实际上不起作用)涉及一个接收索引的函数 #my_func[0] =

是否可以在数据帧中执行动态“where/filter”? 我正在运行“like”操作来删除与特定字符串匹配的项

eventsDF.where(
    ~eventsDF.myColumn.like('FirstString%') &
    ~eventsDF.myColumn.like('anotherString%')
).count()
但是,我需要根据来自另一个数据帧/列表的字符串进行筛选

我想要的解决方案(实际上不起作用)涉及一个接收索引的函数

#my_func[0] = "FirstString"
#my_func[1] = "anotherString"

def my_func(n):
   return str(item[n])

newDf.where(
   ~newDf.useragent.like(str(my_func(1))+'%')
).count()
但我通过传递一个范围(主要是因为它是一个列表而不是一个整数)来努力使它工作


我不想使用“exec”或“eval”来执行它

str_likes=[~df.column.like(s)表示字符串中的s]
然后将其简化为一个表达式
reduce(lambda x,y:x&y,str_likes)

这有点难看,但你想怎么做就怎么做。您也可以在for循环中这样做

bool_expr = ~df.column.like(strings[0])
for s in strings[1:]:
    bool_expr &= ~df.column.like(s)
df.where(bool_expr).count()
bool_expr = ~df.column.like(strings[0])
for s in strings[1:]:
    bool_expr &= ~df.column.like(s)
df.where(bool_expr).count()