import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import io
from io import BytesIO
from zipfile import ZipFile
import requests
from urllib.request import urlopen
#https://stackoverflow.com/questions/9419162/download-returned-zip-file-from-url/51292933
maxurl = "http://www.bom.gov.au/jsp/ncc/cdio/weatherData/av?p_display_type=dailyZippedDataFile&p_stn_num=023034&p_c=-106121997&p_nccObsCode=122&p_startYear=2021"
minurl = "http://www.bom.gov.au/jsp/ncc/cdio/weatherData/av?p_display_type=dailyZippedDataFile&p_stn_num=023034&p_c=-106122193&p_nccObsCode=123&p_startYear=2021"
r = requests.get(maxurl)
z = zipfile.ZipFile(io.BytesIO(r.content))
files = z.namelist()
amax = pd.read_csv(z.open(files[0]))
r = requests.get(minurl)
z = zipfile.ZipFile(io.BytesIO(r.content))
files = z.namelist()
amin = pd.read_csv(z.open(files[0]))
amin.head(1)
Product code | Bureau of Meteorology station number | Year | Month | Day | Minimum temperature (Degree C) | Days of accumulation of minimum temperature | Quality | |
---|---|---|---|---|---|---|---|---|
0 | IDCJAC0011 | 23034 | 1955 | 1 | 1 | NaN | NaN | NaN |
amax.head(1)
Product code | Bureau of Meteorology station number | Year | Month | Day | Maximum temperature (Degree C) | Days of accumulation of maximum temperature | Quality | |
---|---|---|---|---|---|---|---|---|
0 | IDCJAC0010 | 23034 | 1955 | 1 | 1 | NaN | NaN | NaN |
amax.describe()
Bureau of Meteorology station number | Year | Month | Day | Maximum temperature (Degree C) | Days of accumulation of maximum temperature | |
---|---|---|---|---|---|---|
count | 24199.0 | 24199.000000 | 24199.000000 | 24199.000000 | 24152.000000 | 24151.0 |
mean | 23034.0 | 1987.627712 | 6.505806 | 15.728005 | 21.553867 | 1.0 |
std | 0.0 | 19.126351 | 3.453677 | 8.800659 | 6.323200 | 0.0 |
min | 23034.0 | 1955.000000 | 1.000000 | 1.000000 | 9.800000 | 1.0 |
25% | 23034.0 | 1971.000000 | 4.000000 | 8.000000 | 16.400000 | 1.0 |
50% | 23034.0 | 1988.000000 | 7.000000 | 16.000000 | 20.400000 | 1.0 |
75% | 23034.0 | 2004.000000 | 10.000000 | 23.000000 | 25.400000 | 1.0 |
max | 23034.0 | 2021.000000 | 12.000000 | 31.000000 | 45.800000 | 1.0 |
print(amin.shape), print(amax.shape)
(24200, 8) (24199, 8)
(None, None)
ade = amin.merge(amax, how="inner", on=["Year","Month","Day"])
ade.head(1)
Product code_x | Bureau of Meteorology station number_x | Year | Month | Day | Minimum temperature (Degree C) | Days of accumulation of minimum temperature | Quality_x | Product code_y | Bureau of Meteorology station number_y | Maximum temperature (Degree C) | Days of accumulation of maximum temperature | Quality_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | IDCJAC0011 | 23034 | 1955 | 1 | 1 | NaN | NaN | NaN | IDCJAC0010 | 23034 | NaN | NaN | NaN |
ade.shape
(24199, 13)
ade = ade.dropna(subset=["Minimum temperature (Degree C)"])
ade.shape
(24145, 13)
ade.head(1)
Product code_x | Bureau of Meteorology station number_x | Year | Month | Day | Minimum temperature (Degree C) | Days of accumulation of minimum temperature | Quality_x | Product code_y | Bureau of Meteorology station number_y | Maximum temperature (Degree C) | Days of accumulation of maximum temperature | Quality_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
46 | IDCJAC0011 | 23034 | 1955 | 2 | 16 | 16.1 | NaN | Y | IDCJAC0010 | 23034 | 24.0 | NaN | Y |
ade.dtypes
Product code_x object Bureau of Meteorology station number_x int64 Year int64 Month int64 Day int64 Minimum temperature (Degree C) float64 Days of accumulation of minimum temperature float64 Quality_x object Product code_y object Bureau of Meteorology station number_y int64 Maximum temperature (Degree C) float64 Days of accumulation of maximum temperature float64 Quality_y object dtype: object
ax2 = ade.plot.scatter(x='Minimum temperature (Degree C)',y='Maximum temperature (Degree C)',c='Year',colormap="viridis")
adeG = ade.groupby(['Year','Month']).mean()
adeG
Bureau of Meteorology station number_x | Day | Minimum temperature (Degree C) | Days of accumulation of minimum temperature | Bureau of Meteorology station number_y | Maximum temperature (Degree C) | Days of accumulation of maximum temperature | ||
---|---|---|---|---|---|---|---|---|
Year | Month | |||||||
1955 | 2 | 23034.0 | 22.0 | 14.569231 | 1.0 | 23034.0 | 25.900000 | 1.0 |
3 | 23034.0 | 16.0 | 13.990323 | 1.0 | 23034.0 | 25.274194 | 1.0 | |
4 | 23034.0 | 15.5 | 10.906667 | 1.0 | 23034.0 | 21.840000 | 1.0 | |
5 | 23034.0 | 16.0 | 8.600000 | 1.0 | 23034.0 | 16.729032 | 1.0 | |
6 | 23034.0 | 15.5 | 8.440000 | 1.0 | 23034.0 | 15.196667 | 1.0 | |
... | ... | ... | ... | ... | ... | ... | ... | ... |
2020 | 12 | 23034.0 | 16.0 | 14.706452 | 1.0 | 23034.0 | 25.548387 | 1.0 |
2021 | 1 | 23034.0 | 16.0 | 16.648387 | 1.0 | 23034.0 | 27.896774 | 1.0 |
2 | 23034.0 | 14.5 | 15.957143 | 1.0 | 23034.0 | 26.285714 | 1.0 | |
3 | 23034.0 | 16.0 | 14.300000 | 1.0 | 23034.0 | 24.990323 | 1.0 | |
4 | 23034.0 | 1.5 | 12.800000 | 1.0 | 23034.0 | 31.850000 | 1.0 |
795 rows × 7 columns
ax3 = adeG.plot.scatter(x='Minimum temperature (Degree C)',y='Maximum temperature (Degree C)',colormap="viridis")
adeG = adeG.add_suffix('_Mean').reset_index()
adeG
Year | Month | Bureau of Meteorology station number_x_Mean | Day_Mean | Minimum temperature (Degree C)_Mean | Days of accumulation of minimum temperature_Mean | Bureau of Meteorology station number_y_Mean | Maximum temperature (Degree C)_Mean | Days of accumulation of maximum temperature_Mean | |
---|---|---|---|---|---|---|---|---|---|
0 | 1955 | 2 | 23034.0 | 22.0 | 14.569231 | 1.0 | 23034.0 | 25.900000 | 1.0 |
1 | 1955 | 3 | 23034.0 | 16.0 | 13.990323 | 1.0 | 23034.0 | 25.274194 | 1.0 |
2 | 1955 | 4 | 23034.0 | 15.5 | 10.906667 | 1.0 | 23034.0 | 21.840000 | 1.0 |
3 | 1955 | 5 | 23034.0 | 16.0 | 8.600000 | 1.0 | 23034.0 | 16.729032 | 1.0 |
4 | 1955 | 6 | 23034.0 | 15.5 | 8.440000 | 1.0 | 23034.0 | 15.196667 | 1.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
790 | 2020 | 12 | 23034.0 | 16.0 | 14.706452 | 1.0 | 23034.0 | 25.548387 | 1.0 |
791 | 2021 | 1 | 23034.0 | 16.0 | 16.648387 | 1.0 | 23034.0 | 27.896774 | 1.0 |
792 | 2021 | 2 | 23034.0 | 14.5 | 15.957143 | 1.0 | 23034.0 | 26.285714 | 1.0 |
793 | 2021 | 3 | 23034.0 | 16.0 | 14.300000 | 1.0 | 23034.0 | 24.990323 | 1.0 |
794 | 2021 | 4 | 23034.0 | 1.5 | 12.800000 | 1.0 | 23034.0 | 31.850000 | 1.0 |
795 rows × 9 columns
adeMar = adeG.loc[adeG['Month'] == 3]
adeMar.shape
(67, 9)
ax4 = adeMar.plot.scatter(x='Minimum temperature (Degree C)_Mean',y='Maximum temperature (Degree C)_Mean',c='Year',colormap="viridis")
ax4 = adeMar.plot.line(y='Maximum temperature (Degree C)_Mean',colormap="viridis")
# multiple line plots
plt.figure(figsize=(8,8))
plt.plot( 'Minimum temperature (Degree C)_Mean', data=adeMar, marker='o', markerfacecolor='blue', markersize=12, color='skyblue', linewidth=4)
plt.plot( 'Maximum temperature (Degree C)_Mean', data=adeMar, marker='x', markerfacecolor='red', markersize=12, color='orange', linewidth=4)
# show legend
plt.legend()
# show graph
plt.show()
adeMarDay = ade.loc[ade['Month']==3]
# multiple line plots
adeMarDay = ade.loc[ade['Month']==3]
plt.figure(figsize=(30,30))
plt.plot( 'Minimum temperature (Degree C)', data=adeMarDay, marker='o', markerfacecolor='blue', markersize=12, color='skyblue', linewidth=4)
plt.plot( 'Maximum temperature (Degree C)', data=adeMarDay, marker='x', markerfacecolor='red', markersize=12, color='orange', linewidth=4)
# show legend
plt.legend()
# show graph
plt.show()
ade.loc[(ade['Month'] ==3) & (ade['Year'] >1988)].mean()
Bureau of Meteorology station number_x 23034.000000 Year 2005.000000 Month 3.000000 Day 16.000000 Minimum temperature (Degree C) 14.891593 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 25.665591 Days of accumulation of maximum temperature 1.000000 dtype: float64
for i in range(1,13):
print(i)
print(ade.loc[(ade['Month'] ==i) & (ade['Year'] <=1988)].mean())
print(ade.loc[(ade['Month'] ==i) & (ade['Year'] >1988)].mean())
1 Bureau of Meteorology station number_x 23034.000000 Year 1972.000000 Month 1.000000 Day 16.000000 Minimum temperature (Degree C) 15.435679 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 27.854154 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2005.000000 Month 1.000000 Day 16.000000 Minimum temperature (Degree C) 16.817302 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 28.548387 Days of accumulation of maximum temperature 1.000000 dtype: float64 2 Bureau of Meteorology station number_x 23034.000000 Year 1971.766385 Month 2.000000 Day 14.741015 Minimum temperature (Degree C) 15.703488 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 27.873044 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2005.008584 Month 2.000000 Day 14.624464 Minimum temperature (Degree C) 16.710408 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 28.234227 Days of accumulation of maximum temperature 1.000000 dtype: float64 3 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 3.000000 Day 16.000000 Minimum temperature (Degree C) 14.166698 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 25.384250 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2005.000000 Month 3.000000 Day 16.000000 Minimum temperature (Degree C) 14.891593 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 25.665591 Days of accumulation of maximum temperature 1.000000 dtype: float64 4 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 4.000000 Day 15.500000 Minimum temperature (Degree C) 11.617941 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 22.104510 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.534304 Month 4.000000 Day 15.470894 Minimum temperature (Degree C) 12.145010 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 22.457277 Days of accumulation of maximum temperature 1.000000 dtype: float64 5 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 5.000000 Day 16.000000 Minimum temperature (Degree C) 9.379127 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 18.400095 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 5.000000 Day 16.000000 Minimum temperature (Degree C) 9.955242 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 18.760282 Days of accumulation of maximum temperature 1.000000 dtype: float64 6 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 6.000000 Day 15.500000 Minimum temperature (Degree C) 7.369314 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 15.963137 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 6.000000 Day 15.500000 Minimum temperature (Degree C) 7.926146 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 15.898438 Days of accumulation of maximum temperature 1.000000 dtype: float64 7 Bureau of Meteorology station number_x 23034.000000 Year 1971.473384 Month 7.000000 Day 16.002852 Minimum temperature (Degree C) 6.823954 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 14.853327 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 7.000000 Day 16.000000 Minimum temperature (Degree C) 7.377722 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 15.163105 Days of accumulation of maximum temperature 1.000000 dtype: float64 8 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 8.000000 Day 16.000000 Minimum temperature (Degree C) 7.479696 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 15.876281 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 8.000000 Day 16.000000 Minimum temperature (Degree C) 7.707560 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 16.033367 Days of accumulation of maximum temperature 1.000000 dtype: float64 9 Bureau of Meteorology station number_x 23034.000000 Year 1971.483808 Month 9.000000 Day 15.504416 Minimum temperature (Degree C) 8.623160 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 17.874289 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 9.000000 Day 15.500000 Minimum temperature (Degree C) 9.369375 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 18.701563 Days of accumulation of maximum temperature 1.000000 dtype: float64 10 Bureau of Meteorology station number_x 23034.000000 Year 1971.485252 Month 10.000000 Day 16.007612 Minimum temperature (Degree C) 10.418934 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 20.795243 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.511604 Month 10.000000 Day 15.990918 Minimum temperature (Degree C) 11.120484 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 21.622020 Days of accumulation of maximum temperature 1.000000 dtype: float64 11 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 11.000000 Day 15.500000 Minimum temperature (Degree C) 12.284608 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 23.536667 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.515120 Month 11.000000 Day 15.504692 Minimum temperature (Degree C) 13.557873 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 24.596559 Days of accumulation of maximum temperature 1.000000 dtype: float64 12 Bureau of Meteorology station number_x 23034.000000 Year 1971.500000 Month 12.000000 Day 16.000000 Minimum temperature (Degree C) 14.138046 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 25.514421 Days of accumulation of maximum temperature 1.000000 dtype: float64 Bureau of Meteorology station number_x 23034.000000 Year 2004.500000 Month 12.000000 Day 16.000000 Minimum temperature (Degree C) 15.191230 Days of accumulation of minimum temperature 1.000000 Bureau of Meteorology station number_y 23034.000000 Maximum temperature (Degree C) 26.312198 Days of accumulation of maximum temperature 1.000000 dtype: float64