forked from spark-examples/pyspark-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyspark-repace-null.py
More file actions
38 lines (28 loc) · 836 Bytes
/
pyspark-repace-null.py
File metadata and controls
38 lines (28 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
author SparkByExamples.com
"""
from pyspark.sql import SparkSession
spark = SparkSession.builder \
.master("local[1]") \
.appName("SparkByExamples.com") \
.getOrCreate()
filePath="resources/small_zipcode.csv"
df = spark.read.options(header='true', inferSchema='true') \
.csv(filePath)
df.printSchema()
df.show(truncate=False)
df.fillna(value=0).show()
df.fillna(value=0,subset=["population"]).show()
df.na.fill(value=0).show()
df.na.fill(value=0,subset=["population"]).show()
df.fillna(value="").show()
df.na.fill(value="").show()
df.fillna("unknown",["city"]) \
.fillna("",["type"]).show()
df.fillna({"city": "unknown", "type": ""}) \
.show()
df.na.fill("unknown",["city"]) \
.na.fill("",["type"]).show()
df.na.fill({"city": "unknown", "type": ""}) \
.show()