[英]pyspark how to return the average of a column based on the value of another column?
[英]How to check if a column is null based on value of another column in pyspark?
如果特定date_stamp
處的vin
為 null,如何使我的條件打印為 True?
葡萄酒 | 比納爾 | 日期 |
---|---|---|
null | eqr21144 | 2021 年 2 月 2 日 |
Ebntyure43 | Evirter45 | 02-03-2021 |
date_stamp = "02-02-2021"
df2 = df.withColumn(vin,F.when(F.col('date')==F.lit(date_stamp)).isnull())
if df2==True:
print('True')
else:
print('False')
您無法測試 dataframe 是真還是假。 您需要測試列,並使用head()[0]
收集結果:
result = df.filter(F.col('date')==F.lit(date_stamp)).select(F.col('vin').isNull()).head()[0]
然后你可以使用類似 if result
if result: print('True')
你也可以這樣寫:
df2 = df.filter("date = '02-02-2021' AND vin IS NULL")
if df2.count():
print(True)
else:
print(False)
如果df2.count > 0
表示該日期date = 02-02-2021
02-02-2021 的vin
中至少有一個 null 值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.