-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhava.py
89 lines (75 loc) · 4.21 KB
/
hava.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
#Kütüphanelerin yüklenmesi
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
#Verilerin okutulması
df = pd.read_csv("tr.csv",encoding='iso-8859-9')
#Veri tiplerinin dönüştürülmesi
df["Tarih"] = pd.to_datetime(df["Tarih"])
#Grafiklerin oluşturulması
df[['PM10', 'Şehir']].groupby(['Şehir']).median().sort_values("PM10", ascending = False).plot.bar()
df[['SO2', 'Şehir']].groupby(['Şehir']).median().sort_values("SO2", ascending = False).plot.bar()
df[['CO', 'Şehir']].groupby(['Şehir']).median().sort_values("CO", ascending = False).plot.bar()
df[['NO2', 'Şehir']].groupby(['Şehir']).median().sort_values("NO2", ascending = False).plot.bar()
df[['NOX', 'Şehir']].groupby(['Şehir']).median().sort_values("NOX", ascending = False).plot.bar()
df[['NO', 'Şehir']].groupby(['Şehir']).median().sort_values("NO", ascending = False).plot.bar()
df[['O3', 'Şehir']].groupby(['Şehir']).median().sort_values("O3", ascending = False).plot.bar()
#Tüm sütunların dağılım grafikleri
sns.set()
cols = ["PM10", 'SO2', 'CO', 'NO2', 'NOX',"NO","O3"]
sns.pairplot(df[cols], size = 2.5)
plt.show()
#Korelasyon matrisi
corrmat = df.corr()
f, ax = plt.subplots(figsize = (15, 10))
sns.heatmap(corrmat, vmax = 1, square = True, annot = True)
#Ay kolonu oluşturma
df['Tarih'] = pd.to_datetime(df['Tarih'], format = '%M/%d/%y')
df['Ay'] = df['Tarih'].dt.month # year
df['Ay'] = df['Ay'].fillna(0.0).astype(int)
df = df[(df['Ay']>0)]
#Şehirler baz alınarak değerlere göre oluşturulan ısı haritaları
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('PM10'))
sns.heatmap(df.pivot_table('PM10', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("pm10_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('SO2'))
sns.heatmap(df.pivot_table('SO2', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("so2_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (20,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('CO'))
sns.heatmap(df.pivot_table('CO', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("co_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('NO2'))
sns.heatmap(df.pivot_table('NO2', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("no2_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('NOX'))
sns.heatmap(df.pivot_table('NOX', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("nox_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('NO'))
sns.heatmap(df.pivot_table('NO', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("no_heatmap.png",bbox_inches="tight")
f, ax = plt.subplots(figsize = (10,50))
ax.set_title('{} Şehir Ve Aya Göre'.format('O3'))
sns.heatmap(df.pivot_table('O3', index = 'Şehir',
columns = ['Ay'], aggfunc = 'median', margins=True),
annot = True, cmap = 'YlGnBu', linewidths = 1, ax = ax, cbar_kws = {'label': 'Aylık Alınan Ortalama'})
plt.savefig("o3_heatmap.png",bbox_inches="tight")