Replace null values code example

Example: Replace null values

# Replace null values

df4.na.fill(50).show()
# +---+------+-----+
# |age|height| name|
# +---+------+-----+
# | 10|    80|Alice|
# |  5|    50|  Bob|
# | 50|    50|  Tom|
# | 50|    50| null|
# +---+------+-----+

df5.na.fill(False).show()
# +----+-------+-----+
# | age|   name|  spy|
# +----+-------+-----+
# |  10|  Alice|false|
# |   5|    Bob|false|
# |null|Mallory| true|
# +----+-------+-----+

df4.na.fill({'age': 50, 'name': 'unknown'}).show()
# +---+------+-------+
# |age|height|   name|
# +---+------+-------+
# | 10|    80|  Alice|
# |  5|  null|    Bob|
# | 50|  null|    Tom|
# | 50|  null|unknown|
# +---+------+-------+