【问题标题】:delete records from dataframe where any of the column is null or empty从数据框中删除任何列为空或为空的记录
【发布时间】:2020-05-14 18:37:32
【问题描述】:

有什么方法可以从数据框中删除任何列值为空或为空的记录?

+---+-------+--------+-------------------+-----+----------+
|id |zipcode|type    |city               |state|population|
+---+-------+--------+-------------------+-----+----------+
|1  |704    |STANDARD|                   |PR   |30100     |
|2  |704    |        |PASEO COSTA DEL SUR|PR   |          |
|3  |76166  |UNIQUE  |CINGULAR WIRELESS  |TX   |84000     |
+---+-------+--------+-------------------+-----+----------+

我希望输出是:

+---+-------+------+-----------------+-----+----------+
|id |zipcode|type  |city             |state|population|
+---+-------+------+-----------------+-----+----------+
|4  |76166  |UNIQUE|CINGULAR WIRELESS|TX   |84000     |
+---+-------+------+-----------------+-----+----------+

【问题讨论】:

  • 试试这个:df_name.na.drop() .show(false)
  • 谢谢它的工作。你能在下面提到的帖子上帮助我吗:这将是一个很大的帮助。提前致谢。 stackoverflow.com/questions/61815514/…

标签: scala dataframe apache-spark record is-empty


【解决方案1】:

试试这个:

df
  .na.replace(df.columns,Map("" -> null)) // convert empty strings with null
  .na.drop() // drop nulls and NaNs
  .show()

【讨论】:

【解决方案2】:

试试这个:

df_name.na.drop()
  .show(false)

希望对你有帮助...

【讨论】:

猜你喜欢
  • 2015-06-17
  • 2017-06-13
  • 2021-11-06
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
相关资源
最近更新 更多