-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyse_Global_Warming.py
207 lines (98 loc) · 2.83 KB
/
Analyse_Global_Warming.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import seaborn as sns
import plotly.express as px
from plotly.offline import init_notebook_mode
init_notebook_mode(connected=True)
# In[3]:
global_temp=pd.read_csv('E:/Python/Data/Global_Warming_Spatial_Analysis/GlobalTemperatures.csv')
global_temp.head()
# In[4]:
global_temp['dt'][0].split('-')[0]
# In[5]:
def fetch_year(date):
return date.split('-')[0]
# In[7]:
global_temp['years'] = global_temp['dt'].apply(fetch_year)
# In[8]:
global_temp.head()
# In[10]:
data = global_temp.groupby('years').agg({'LandAverageTemperature':'mean', 'LandAverageTemperatureUncertainty':'mean'}).reset_index()
# In[11]:
data.head()
# In[12]:
data['Uncertainity Top'] = data['LandAverageTemperature'] + data['LandAverageTemperatureUncertainty']
data['Uncertainity Bottom'] = data['LandAverageTemperature'] - data['LandAverageTemperatureUncertainty']
data.head()
# In[13]:
data.columns
# In[15]:
fig=px.line(
data,
x='years', y=['LandAverageTemperature', 'Uncertainity Top', 'Uncertainity Bottom'],
title='Avg Land temp in World'
)
fig.show()
# In[16]:
global_temp['dt'][0].split('-')[1]
# In[17]:
global_temp['dt'] = pd.to_datetime(global_temp['dt'])
# In[18]:
global_temp['month'] = global_temp['dt'].dt.month
global_temp.head()
# In[19]:
def get_season(month):
if month >=3 and month <= 5:
return 'spring'
elif month >=6 and month <= 8:
return 'summer'
elif month >=9 and month <= 11:
return 'autumn'
else:
return 'winter'
# In[20]:
global_temp['season'] = global_temp['month'].apply(get_season)
# In[21]:
global_temp.head()
# In[24]:
years = global_temp['years'].unique()
# In[23]:
years
# In[25]:
spring_temps = []
summer_temps = []
autumn_temps = []
winter_temps = []
# In[27]:
for year in years:
current_df = global_temp[global_temp['years']==year]
spring_temps.append(current_df[current_df['season'] == 'spring']['LandAverageTemperature'].mean())
summer_temps.append(current_df[current_df['season'] == 'summer']['LandAverageTemperature'].mean())
autumn_temps.append(current_df[current_df['season'] == 'autumn']['LandAverageTemperature'].mean())
winter_temps.append(current_df[current_df['season'] == 'winter']['LandAverageTemperature'].mean())
# In[29]:
spring_temps
season = pd.DataFrame()
# In[32]:
season = pd.DataFrame()
season['year'] = years
season['Winter Temp'] = winter_temps
season['Spring Temp'] = spring_temps
season['Summer Temp'] = summer_temps
season['Autumn Temp'] = autumn_temps
# In[33]:
season.head()
# In[34]:
season.columns
# In[36]:
fig = px.line(
season,
x='year',
y=['Winter Temp', 'Spring Temp', 'Summer Temp', 'Autumn Temp'],
title='Season Wise Average Temperage'
)
fig
# In[ ]: