-
Notifications
You must be signed in to change notification settings - Fork 3
/
Data_pre_processing.py
173 lines (150 loc) · 5.29 KB
/
Data_pre_processing.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 2 09:52:37 2020
@author: janibasha
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def Day_values_2013():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2013.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def Day_values_2014():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2014.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def Day_values_2015():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2015.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def Day_values_2016():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2016.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def Day_values_2017():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2017.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
def Day_values_2018():
temp_i=0
average=[]
for rows in pd.read_csv(r'C:\Users\Unify\Desktop\janibasha\Complete Data Science life cycle\Data_collection\AQI\aqi2018.csv',chunksize=24):
add_var=0
avg=0.0
data=[]
df=pd.DataFrame(data=rows)
for index,row in df.iterrows():
data.append(row['PM2.5'])
for i in data:
if type(i) is float or type(i) is int:
add_var=add_var+i
elif type(i) is str:
if i!='NoData' and i!='PwrFail' and i!='---' and i!='InVld':
temp=float(i)
add_var=add_var+temp
avg=add_var/24
temp_i=temp_i+1
average.append(avg)
return average
if __name__=="__main__":
lst2013=Day_values_2013()
lst2014=Day_values_2014()
lst2015=Day_values_2015()
lst2016=Day_values_2016()
lst2017=Day_values_2017()
lst2018=Day_values_2018()
plt.plot(range(0,365),lst2013,label="2013 data")
plt.plot(range(0,364),lst2014,label="2014 data")
plt.plot(range(0,365),lst2015,label="2015 data")
plt.plot(range(0,365),lst2016,label="2016 data")
plt.xlabel('Day')
plt.ylabel('PM 2.5')
plt.legend(loc='upper right')
plt.show()