'where' 在 apache 火花中
'where' in apache spark
df:
-----------+
| word|
+-----------+
| 1609|
| |
| the|
| sonnets|
| |
| by|
| william|
|shakespeare|
| |
| fg|
这是我的数据框。如何使用 'where' 子句删除空行(删除包含 '' 的行)。
code:
df.where(trim(df.word) == "").show()
output:
----+
|word|
+----+
| |
| |
| |
| |
| |
| |
| |
| |
| |
感谢任何帮助。
您可以 trim 并检查结果是否为空:
>>> from pyspark.sql.functions import trim
>>> df.where(trim(df.word) != "")
除了where,您还可以使用filter来实现。
from pyspark.sql.functions import trim
df.filter(trim(df.word) != "").show()
df.where(trim(df.word) != "").show()
df:
-----------+
| word|
+-----------+
| 1609|
| |
| the|
| sonnets|
| |
| by|
| william|
|shakespeare|
| |
| fg|
这是我的数据框。如何使用 'where' 子句删除空行(删除包含 '' 的行)。
code:
df.where(trim(df.word) == "").show()
output:
----+
|word|
+----+
| |
| |
| |
| |
| |
| |
| |
| |
| |
感谢任何帮助。
您可以 trim 并检查结果是否为空:
>>> from pyspark.sql.functions import trim
>>> df.where(trim(df.word) != "")
除了where,您还可以使用filter来实现。
from pyspark.sql.functions import trim
df.filter(trim(df.word) != "").show()
df.where(trim(df.word) != "").show()