-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMissng_data.py
137 lines (51 loc) · 1.45 KB
/
Missng_data.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# coding: utf-8
# In[10]:
# df.na. (methods) are used to drop the items present in data
from pyspark.sql import SparkSession
#making sparksession as for each different used
# In[11]:
spark = SparkSession.builder.appName('misssing').getOrCreate()
# In[12]:
df = spark.read.csv('/home/tushar/spark-2.3.0-bin-hadoop2.7/python/Python-and-Spark-for-Big-Data-master/Spark_DataFrames/ContainsNull.csv',inferSchema=True,header=True)
# In[13]:
df.show()
# In[14]:
# to get mean and all values
df.describe()
df.mean()
df.describe().show()
# In[15]:
df.columns
# In[16]:
df.printSchema()
# In[17]:
df.show()
# In[19]:
df.na.drop().show()
# In[23]:
# drops those rows which have null values =2
df.na.drop(thresh=2).show()
# In[27]:
(df.na.drop(how='all')).show()
# In[29]:
#drop value for null in sales columnn
df.na.drop(subset=['Sales']).show()
# In[32]:
#########################################
# TO FILL UP THE DATA WHERE NULL IS PRESENT
df.na.fill('No name',subset=('Name')).show()
# In[33]:
df.na.fill(2,subset=('Sales')).show()
# In[34]:
# WE ARE FILLING THE NUMERICAL DATA IN SALES COLUMN WITH THE MEAN VALUE OF THE SALES OF THE DATASET
from pyspark.sql.functions import mean
# In[36]:
sales_mean = df.select(mean('Sales')).collect()
# In[43]:
mean_sales = sales_mean[0][0]
# In[44]:
mean_sales
# In[46]:
df.na.fill(mean_sales,subset=('Sales')).show()
# In[ ]: