-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData analysis hour month dayweek BM.py
155 lines (95 loc) · 4.21 KB
/
Data analysis hour month dayweek BM.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
# -*- coding: utf-8 -*-
"""
@author: anamcilie
"""
def time_variation(df, pollutant, ylabel, hue=None):
# importing all the libraries we'll need
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os
from datetime import datetime
from pandas import Series # To work on series
import statsmodels
import warnings # To ignore the warnings
warnings.filterwarnings("ignore")
import seaborn as sns
sns.set_style("white")
plt.style.use("seaborn")
# Use seaborn style defaults and set the default figure size
sns.set(rc={'figure.figsize':(14, 8)})
# sns.set() # setting to default settings
# plt.rcParams # set default matplotlib settings
# finding the current directory
abs_path = os.getcwd()
abs_path
# change to desired folder where .csv file is present - Use forward backslash
path = r'D:\BM\DATA\IQair VisualAir\2_Ulaanbaatar monitors\IQair Visual monitors\35r surguuli'
data = pd.read_csv(path + '/historical_hourly_data_GASYTU6 PM2.5.csv')
# Exploratory Data Analysis
data.dtypes # find the datatypes of all variables
data.columns # list of all column names - original list
data.shape # Dimensions of original dataset (rows, columns)
print(data.head(10)) # first 10 rows of dataset
#data.index # index - number of rows and columns
data.info() # information on datatypes and number of elements
# Convert the datatype of certain columns to float type
data[['Datetime']] = data[['Datetime']].apply(pd.to_datetime)
#setting xticklabels
week = ['mon','tue','wed','thu','fri','sat','sun']
months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
data.info() # information on datatypes and number of elements
print (data,'PM2.5')
# dropping Nan values
#data = data.dropna()
#data = data.drop(columns=['Temperature_F'], axis = 1)
# Saving the cleaned file into the same folder
#data.to_csv('bayan-Ulgii_01 (outside)_Clean.csv', index=False)
# Creating graphs of pollutant concentrations by hour, month and day of week
fig,axes = plt.subplots(1, 3,sharex=False, figsize=(16,4)) #creating subplots, side by side
fig.tight_layout(pad=2) # makeing plots get closer
sns.set_style('whitegrid')
# concentration vs hour
axes[0] = sns.lineplot(ax=axes[0],data=data,
x=data['Datetime'].dt.hour,
y=data['PM2.5'],
color='red',
linewidth=1.5,
palette="hls")
axes[0].set_xticklabels(axes[0].get_xticks(), fontsize=13)
axes[0].set_yticklabels(axes[0].get_yticks(), fontsize=13)
axes[0].set_xlabel('hour', fontsize=13)
axes[0].set_ylabel('PM2.5 ug/m3', fontsize=13)
axes[0].legend().set_title('35r surguuli')
# concentration vs month
axes[1] = sns.lineplot(ax=axes[1],
data=data,
x=data['Datetime'].dt.month,
y=data['PM2.5'],
color='red',
linewidth=1.5,
palette="hls")
axes[1].set_xticks(np.arange(1, 13, 1))
axes[1].set_xticklabels(months, fontsize=13)
axes[1].set_yticklabels('')
axes[1].set_xlabel('month', fontsize=13)
axes[1].set_ylabel('PM2.5 ug/m3')
axes[1].legend().set_title('35r surguuli')
# concentration vs day of week
axes[2] = sns.lineplot(ax=axes[2],
data=data,
x=data['Datetime'].dt.dayofweek,
y=data['PM2.5'],
color='red',
linewidth=1.5,
palette="hls")
axes[2].set_xticks(np.arange(0, 7, 1))
axes[2].set_xticklabels(week, fontsize=13)
axes[2].set_yticklabels('')
axes[2].set_xlabel('day of week', fontsize=13)
axes[2].set_ylabel('')
axes[2].legend().set_title('35r surguuli')