apache-spark - Apache Spark 中的“哪里”

标签 apache-spark pyspark apache-spark-sql

df:

-----------+
|       word|
+-----------+
|       1609|
|           |
|        the|
|    sonnets|
|           |
|         by|
|    william|
|shakespeare|
|           |
|         fg|

这是我的数据框。如何使用“where”子句删除空行(删除包含“”的行)。

code:

df.where(trim(df.word) == "").show()

output:

----+
|word|
+----+
|    |
|    |
|    |
|    |
|    |
|    |
|    |
|    |
|    |

感谢任何帮助。

最佳答案

您可以修剪并检查结果是否为空:

>>> from pyspark.sql.functions import trim
>>> df.where(trim(df.word) != "")

关于apache-spark - Apache Spark 中的“哪里”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38378315/

相关文章:

python - Pyspark sparkSql 问题

apache-spark - Spark 流可视化

dataframe - 从 Spark 中的数据框列值中删除空格

python - 获取 Spark RDD 中每个键的最大值

mysql - 如何使用scala获取事务中的第一条记录?

apache-spark - Spark Kafka Direct DStream-如果设置了num-executors,则在yarn-cluster模式下有多少个执行器和RDD分区?

python - Pyspark 中的范围分区

apache-spark - Apache Spark Codegen Stage 增长超过 64 KB

apache-spark - 如何均匀分布数据集以避免倾斜连接(和长时间运行的任务)?

python - 调用返回 FloatType() 的 UDF 时为 "expected zero arguments for construction of ClassDict (for numpy.dtype)"