# Based on https://www.kaggle.com/antgoldbloom/exploring-climate-change-data import pandas as pd import sys # Check usage if len(sys.argv) < 2: print("Usage: %s " % sys.argv[0]) sys.exit() csvfile = sys.argv[1] # Sort all cities on average temperature dfTempByCity = pd.read_csv(csvfile,index_col='dt',parse_dates=[0]) cities_2012_avg = dfTempByCity[dfTempByCity.index.year == 2012][['City','Country','AverageTemperature']].groupby(['City','Country']).mean().sort_values('AverageTemperature',ascending=False) print("Cities with highest average temperature in 2012:") print(cities_2012_avg.head()) print("") print("Cities with lowest average temperature in 2012:") print(cities_2012_avg.tail()) #Temperature in Groningen using a 12 month rolling mean to smooth out seasonality plot = pd.Series.rolling(dfTempByCity[dfTempByCity['City'] == 'Groningen']['AverageTemperature'],window=12).mean().plot(x=dfTempByCity.index) plot.get_figure().savefig('plot.png')