antitheft159 commited on
Commit
1bbe34b
·
verified ·
1 Parent(s): ad16793

Upload gaqdaqi_321_890.py

Browse files
Files changed (1) hide show
  1. gaqdaqi_321_890.py +152 -0
gaqdaqi_321_890.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """GAQDAQI.321.890
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/10yCiraevWJgKWVmJno07vSCNVIvsiA8q
8
+ """
9
+
10
+ import pandas as pd
11
+
12
+ file_path = '/content/global_air_quality_data_10000.csv'
13
+ df_air_quality = pd.read_csv(file_path)
14
+
15
+ df_air_quality.head()
16
+
17
+ df_air_quality.info()
18
+
19
+ df_air_quality.describe(include='all')
20
+
21
+ df_air_quality.isnull().sum()
22
+
23
+ df_air_quality.isnull().sum()
24
+
25
+ df_air_quality.describe(include='all')
26
+
27
+ import matplotlib.pyplot as plt
28
+ import seaborn as sns
29
+
30
+ plt.figure(figsize=(10, 6))
31
+ sns.histplot(df_air_quality['PM2.5'], bins=30, kde=True)
32
+ plt.title('Distribution of PM2.5')
33
+ plt.xlabel('PM2.5')
34
+ plt.ylabel('Frequency')
35
+ plt.show()
36
+
37
+ plt.figure(figsize=(12, 6))
38
+ plt.plot(df_air_quality['Date'], df_air_quality['PM2.5'])
39
+ plt.title('PM2.5 Levels Over Time')
40
+ plt.xlabel('Date')
41
+ plt.ylabel('PM2.5')
42
+ plt.show()
43
+
44
+ plt.figure(figsize=(15, 8))
45
+ sns.boxplot(x='City', y='PM2.5', data=df_air_quality)
46
+ plt.title('PM2.5 Levels by City')
47
+ plt.xlabel('City')
48
+ plt.ylabel('PM2.5')
49
+ plt.xticks(rotation=90)
50
+ plt.show()
51
+
52
+ numeric_cols = df_air_quality.select_dtypes(include=['number'])
53
+
54
+ plt.figure(figsize=(12, 10))
55
+ sns.heatmap(numeric_cols.corr(), annot=True, cmap='coolwarm', linewidths=0.5)
56
+ plt.title('Correlation Heatmap')
57
+ plt.show()
58
+
59
+ plt.figure(figsize=(10, 6))
60
+ sns.scatterplot(x='PM2.5', y='PM10', data=df_air_quality)
61
+ plt.title('Scatter Plot of PM2.5 vs. PM10')
62
+ plt.xlabel('PM2.5')
63
+ plt.ylabel('PM10')
64
+ plt.show()
65
+
66
+ city_pollutants_mean = df_air_quality.groupby('City')[['PM2.5', 'PM10', 'NO2', 'SO2', 'CO', 'O3']].mean()
67
+ city_pollutants_mean
68
+
69
+ plt.figure(figsize=(15, 8))
70
+ city_pollutants_mean['PM2.5'].plot(kind='bar')
71
+ plt.title('Mean PM2.5 Levels by City')
72
+ plt.xlabel('City')
73
+ plt.ylabel('Mean PM2.5')
74
+ plt.xticks(rotation=90)
75
+ plt.show()
76
+
77
+ sns.pairplot(df_air_quality[['PM2.5', 'PM10', 'NO2', 'SO2', 'CO', 'O3']])
78
+ plt.suptitle('Pair Plot of Selected Pollutants', y=1.02)
79
+ plt.show()
80
+
81
+ import matplotlib.pyplot as plt
82
+ import seaborn as sns
83
+ import pandas as pd
84
+ import numpy as np
85
+
86
+ data = {
87
+ 'Date': pd.date_range(start='1/1/2020', periods=100, freq='D'),
88
+ 'PM2.5' : np.random.rand(100) * 100,
89
+ 'OtherMetric': np.random.rand(100) * 50
90
+ }
91
+ df_air_quality = pd.DataFrame(data)
92
+
93
+ df_air_quality['Date'] = pd.to_datetime(df_air_quality['Date'])
94
+ df_air_quality.set_index('Date', inplace= True)
95
+
96
+ seasonal_trends = df_air_quality.resample('M').mean(numeric_only=True)
97
+
98
+ plt.figure(figsize=(12, 8))
99
+ plt.plot(seasonal_trends)
100
+ plt.title('Seasonal Trends in Air Quallity')
101
+ plt.xlabel('Month')
102
+ plt.ylabel('Mean Value')
103
+ plt.legend(seasonal_trends.columns, loc='upper right')
104
+ plt.show()
105
+
106
+ import matplotlib.pyplot as plt
107
+ import seaborn as sns
108
+ import pandas as pd
109
+ import numpy as np
110
+
111
+ # Example DataFrame creation (Replace this with your actual data loading step)
112
+ data = {
113
+ 'Date': pd.date_range(start='1/1/2020', periods=100, freq='D'),
114
+ 'Country': np.random.choice(['USA', 'China', 'India', 'Germany', 'Brazil'], 100),
115
+ 'PM2.5': np.random.rand(100) * 100,
116
+ 'PM10': np.random.rand(100) * 150,
117
+ 'NO2': np.random.rand(100) * 50,
118
+ 'SO2': np.random.rand(100) * 20,
119
+ 'CO': np.random.rand(100) * 10,
120
+ 'O3': np.random.rand(100) * 70,
121
+ 'OtherMetric': np.random.rand(100) * 50
122
+ }
123
+ df_air_quality = pd.DataFrame(data)
124
+
125
+ # Ensure the Date column is in datetime format and set it as the index
126
+ df_air_quality['Date'] = pd.to_datetime(df_air_quality['Date'])
127
+ df_air_quality.set_index('Date', inplace=True)
128
+
129
+ # Group by country and compute mean of pollutants
130
+ country_pollutants_mean = df_air_quality.groupby('Country')[['PM2.5', 'PM10', 'NO2', 'SO2', 'CO', 'O3']].mean()
131
+ print(country_pollutants_mean)
132
+
133
+ # Plot the mean values of pollutants by country
134
+ fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(15, 15))
135
+
136
+ pollutants = ['PM2.5', 'PM10', 'NO2', 'SO2', 'CO', 'O3']
137
+ for i, pollutant in enumerate(pollutants):
138
+ row, col = divmod(i, 2)
139
+ sns.barplot(x=country_pollutants_mean.index, y=country_pollutants_mean[pollutant], ax=axes[row, col])
140
+ axes[row, col].set_title(f'Mean {pollutant} by Country')
141
+ axes[row, col].set_xlabel('Country')
142
+ axes[row, col].set_ylabel(f'Mean {pollutant}')
143
+
144
+ plt.tight_layout()
145
+ plt.show()
146
+
147
+ plt.figure(figsize=(15, 10))
148
+ sns.heatmap(country_pollutants_mean, annot=True, cmap= 'YlGnBu', linewidths=0.5)
149
+ plt.title('Mean Pollutant Levels by Country')
150
+ plt.xlabel('Pollutants')
151
+ plt.ylabel('Country')
152
+ plt.show()