![](/img/trans.png)
[英]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.