簡體   English   中英

如何用 lambda function 為 pyspark 數據幀編寫 reduce?

[英]How to write reduce with lambda function for pyspark data-frame?

我想用 lambda 實現 reduce function。例如,如果有 pyspark 數據框並且在某個列上,我想獲取那些列值長度在某個范圍之間的所有記錄。 這是如何使用 reduce function 和 lambda 來實現的。我嘗試用下面的代碼來實現它,但我不太確定。

bad_df = reduce(lambda x, (min < f.col(x) < max for x in df.columns if x in col_list))

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


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM