Temperature and Severe Weather Occurences in Southern Maine

a search for correlation

May 9, 2016


In [101]:
import openpyxl
import sys                             # system module 
import pandas as pd                    # data package
import matplotlib.pyplot as plt        # graphics module  
import datetime as dt                  # date and time module
import numpy as np                     # foundation for Pandas 
from pandas_datareader import data, wb 
%matplotlib inline 
import seaborn as sns

# check versions (overkill, but why not?)
print('Python version: ', sys.version)
print('Pandas version: ', pd.__version__)
print('Today: ', dt.date.today())


Python version:  3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec  7 2015, 11:24:55) 
[GCC 4.2.1 (Apple Inc. build 5577)]
Pandas version:  0.18.0
Today:  2016-05-07

In [300]:
##Recordings of severe weather in York, Maine, from 1996 to 2015:

storms = pd.read_excel('/Users/jamesalbright/Desktop/Bootcamp Final Master Data.xlsx')
print('Dimensions:', storms.shape)
print('Variable dtypes:\n', storms.dtypes, sep='')
storms.head


Dimensions: (864, 10)
Variable dtypes:
CZ_NAME_STR                    object
BEGIN_DATE             datetime64[ns]
EVENT_TYPE                     object
MAGNITUDE                      object
DAMAGE_PROPERTY_NUM             int64
EPISODE_ID                      int64
CZ_FIPS                         int64
Unnamed: 7                     object
Unnamed: 8                     object
Unnamed: 9                    float64
dtype: object
Out[300]:
<bound method NDFrame.head of               CZ_NAME_STR BEGIN_DATE         EVENT_TYPE MAGNITUDE  \
0     COASTAL YORK (ZONE) 1996-01-03         Heavy Snow             
1    INTERIOR YORK (ZONE) 1996-01-03         Heavy Snow             
2    INTERIOR YORK (ZONE) 1996-01-08         Heavy Snow             
3     COASTAL YORK (ZONE) 1996-01-08         Heavy Snow             
4     COASTAL YORK (ZONE) 1996-01-12         Heavy Snow             
5    INTERIOR YORK (ZONE) 1996-01-12         Heavy Snow             
6    INTERIOR YORK (ZONE) 1996-01-19          High Wind             
7     COASTAL YORK (ZONE) 1996-01-19          High Wind             
8    INTERIOR YORK (ZONE) 1996-01-27     Winter Weather             
9     COASTAL YORK (ZONE) 1996-01-27          High Wind             
10   INTERIOR YORK (ZONE) 1996-02-25          High Wind             
11    COASTAL YORK (ZONE) 1996-03-05         Heavy Snow             
12   INTERIOR YORK (ZONE) 1996-03-05         Heavy Snow             
13    COASTAL YORK (ZONE) 1996-03-07         Heavy Snow             
14   INTERIOR YORK (ZONE) 1996-03-07         Heavy Snow             
15   INTERIOR YORK (ZONE) 1996-04-09         Heavy Snow             
16    COASTAL YORK (ZONE) 1996-04-09         Heavy Snow             
17   INTERIOR YORK (ZONE) 1996-04-16         Heavy Rain             
18    COASTAL YORK (ZONE) 1996-04-16         Heavy Rain             
19   INTERIOR YORK (ZONE) 1996-04-16              Flood             
20    COASTAL YORK (ZONE) 1996-04-16              Flood             
21    COASTAL YORK (ZONE) 1996-04-16      Coastal Flood             
22               YORK CO. 1996-05-12        Flash Flood             
23               YORK CO. 1996-07-08               Hail      1.75   
24               YORK CO. 1996-07-08               Hail      1.75   
25               YORK CO. 1996-07-08               Hail      0.75   
26               YORK CO. 1996-07-08               Hail       1.5   
27               YORK CO. 1996-07-16  Thunderstorm Wind             
28               YORK CO. 1996-07-16  Thunderstorm Wind             
29               YORK CO. 1996-07-16  Thunderstorm Wind             
..                    ...        ...                ...       ...   
834   COASTAL YORK (ZONE) 2015-02-02         Heavy Snow             
835   COASTAL YORK (ZONE) 2015-02-07         Heavy Snow             
836  INTERIOR YORK (ZONE) 2015-02-14         Heavy Snow             
837   COASTAL YORK (ZONE) 2015-02-14         Heavy Snow             
838   COASTAL YORK (ZONE) 2015-02-15      Coastal Flood             
839  INTERIOR YORK (ZONE) 2015-02-18         Heavy Snow             
840   COASTAL YORK (ZONE) 2015-04-20      Coastal Flood             
841              YORK CO. 2015-05-28  Thunderstorm Wind        50   
842              YORK CO. 2015-05-28  Thunderstorm Wind        50   
843              YORK CO. 2015-05-28  Thunderstorm Wind        50   
844              YORK CO. 2015-06-23  Thunderstorm Wind        50   
845              YORK CO. 2015-07-19               Hail      2.75   
846              YORK CO. 2015-07-19               Hail         1   
847              YORK CO. 2015-07-19  Thunderstorm Wind        50   
848              YORK CO. 2015-07-19  Thunderstorm Wind        50   
849              YORK CO. 2015-07-19  Thunderstorm Wind        50   
850              YORK CO. 2015-08-04  Thunderstorm Wind        50   
851              YORK CO. 2015-08-04               Hail      0.75   
852              YORK CO. 2015-08-04               Hail         2   
853              YORK CO. 2015-08-04               Hail       1.5   
854              YORK CO. 2015-08-04               Hail         1   
855              YORK CO. 2015-08-04               Hail      1.75   
856              YORK CO. 2015-08-04               Hail         1   
857              YORK CO. 2015-08-04               Hail      0.75   
858              YORK CO. 2015-08-04               Hail       2.5   
859              YORK CO. 2015-08-04               Hail         1   
860   COASTAL YORK (ZONE) 2015-09-30      Coastal Flood             
861   COASTAL YORK (ZONE) 2015-10-29      Coastal Flood             
862   COASTAL YORK (ZONE) 2015-12-29         Heavy Snow             
863  INTERIOR YORK (ZONE) 2015-12-29         Heavy Snow             

     DAMAGE_PROPERTY_NUM  EPISODE_ID  CZ_FIPS Unnamed: 7 Unnamed: 8  \
0                      0     2041201       23        NaN        NaN   
1                      0     2041201       18        NaN        NaN   
2                      0     2041202       18        NaN        NaN   
3                      0     2041202       23        NaN        NaN   
4                      0     2041204       23        NaN        NaN   
5                      0     2041204       18        NaN        NaN   
6                      0     2041206       18        NaN        NaN   
7                      0     2041206       23        NaN        NaN   
8                      0     2041208       18        NaN        NaN   
9                      0     2041209       23        NaN        NaN   
10                     0     2041224       18        NaN        NaN   
11                     0     2055154       23        NaN        NaN   
12                     0     2055154       18        NaN        NaN   
13                     0     2055155       23        NaN        NaN   
14                     0     2055155       18        NaN        NaN   
15                     0     2054860       18        NaN        NaN   
16                     0     2054860       23        NaN        NaN   
17                     0     2054862       18        NaN        NaN   
18                     0     2054862       23        NaN        NaN   
19                     0     2054864       18        NaN        NaN   
20                820000     2054864       23        NaN        NaN   
21                     0     2054863       23        NaN        NaN   
22                     0     2055784       31        NaN        NaN   
23                     0     2055796       31        NaN        NaN   
24                     0     2055797       31        NaN        NaN   
25                     0     2055798       31        NaN        NaN   
26                     0     2055799       31        NaN        NaN   
27                     0     2055810       31        NaN        NaN   
28                     0     2055811       31        NaN        NaN   
29                     0     2055812       31        NaN        NaN   
..                   ...         ...      ...        ...        ...   
834                    0       93914       23        NaN        NaN   
835                    0       93904       23        NaN        NaN   
836                    0       93897       18        NaN        NaN   
837                    0       93897       23        NaN        NaN   
838                 5000       93118       23        NaN        NaN   
839                    0       93885       18        NaN        NaN   
840               125000       95443       23        NaN        NaN   
841                    0       96583       31        NaN        NaN   
842                    0       96583       31        NaN        NaN   
843                    0       96583       31        NaN        NaN   
844                    0       98095       31        NaN        NaN   
845                    0       98969       31        NaN        NaN   
846                    0       98969       31        NaN        NaN   
847                    0       98969       31        NaN        NaN   
848                    0       98969       31        NaN        NaN   
849                    0       98969       31        NaN        NaN   
850                    0      100161       31        NaN        NaN   
851                    0      100161       31        NaN        NaN   
852                    0      100161       31        NaN        NaN   
853                    0      100161       31        NaN        NaN   
854                    0      100161       31        NaN        NaN   
855                    0      100161       31        NaN        NaN   
856                    0      100161       31        NaN        NaN   
857                    0      100161       31        NaN        NaN   
858                    0      100161       31        NaN        NaN   
859                    0      100161       31        NaN        NaN   
860                75000      100586       23        NaN        NaN   
861                 2000      101799       23        NaN        NaN   
862                    0      102612       23        NaN        NaN   
863                    0      102612       18        NaN        NaN   

     Unnamed: 9  
0           NaN  
1           NaN  
2           NaN  
3           NaN  
4           NaN  
5           NaN  
6           NaN  
7           NaN  
8           NaN  
9           NaN  
10          NaN  
11          NaN  
12          NaN  
13          NaN  
14          NaN  
15          NaN  
16          NaN  
17          NaN  
18          NaN  
19          NaN  
20          NaN  
21          NaN  
22          NaN  
23          NaN  
24          NaN  
25          NaN  
26          NaN  
27          NaN  
28          NaN  
29          NaN  
..          ...  
834         NaN  
835         NaN  
836         NaN  
837         NaN  
838         NaN  
839         NaN  
840         NaN  
841         NaN  
842         NaN  
843         NaN  
844         NaN  
845         NaN  
846         NaN  
847         NaN  
848         NaN  
849         NaN  
850         NaN  
851         NaN  
852         NaN  
853         NaN  
854         NaN  
855         NaN  
856         NaN  
857         NaN  
858         NaN  
859         NaN  
860         NaN  
861         NaN  
862         NaN  
863         NaN  

[864 rows x 10 columns]>

In [3]:
del storms['Unnamed: 8']

In [4]:
del storms['Unnamed: 9']

In [5]:
del storms['Unnamed: 7']

In [6]:
storms.head()


Out[6]:
CZ_NAME_STR BEGIN_DATE EVENT_TYPE MAGNITUDE DAMAGE_PROPERTY_NUM EPISODE_ID CZ_FIPS
0 COASTAL YORK (ZONE) 1996-01-03 Heavy Snow 0 2041201 23
1 INTERIOR YORK (ZONE) 1996-01-03 Heavy Snow 0 2041201 18
2 INTERIOR YORK (ZONE) 1996-01-08 Heavy Snow 0 2041202 18
3 COASTAL YORK (ZONE) 1996-01-08 Heavy Snow 0 2041202 23
4 COASTAL YORK (ZONE) 1996-01-12 Heavy Snow 0 2041204 23

In [7]:
storms = storms.set_index('BEGIN_DATE')

In [8]:
storms


Out[8]:
CZ_NAME_STR EVENT_TYPE MAGNITUDE DAMAGE_PROPERTY_NUM EPISODE_ID CZ_FIPS
BEGIN_DATE
1996-01-03 COASTAL YORK (ZONE) Heavy Snow 0 2041201 23
1996-01-03 INTERIOR YORK (ZONE) Heavy Snow 0 2041201 18
1996-01-08 INTERIOR YORK (ZONE) Heavy Snow 0 2041202 18
1996-01-08 COASTAL YORK (ZONE) Heavy Snow 0 2041202 23
1996-01-12 COASTAL YORK (ZONE) Heavy Snow 0 2041204 23
1996-01-12 INTERIOR YORK (ZONE) Heavy Snow 0 2041204 18
1996-01-19 INTERIOR YORK (ZONE) High Wind 0 2041206 18
1996-01-19 COASTAL YORK (ZONE) High Wind 0 2041206 23
1996-01-27 INTERIOR YORK (ZONE) Winter Weather 0 2041208 18
1996-01-27 COASTAL YORK (ZONE) High Wind 0 2041209 23
1996-02-25 INTERIOR YORK (ZONE) High Wind 0 2041224 18
1996-03-05 COASTAL YORK (ZONE) Heavy Snow 0 2055154 23
1996-03-05 INTERIOR YORK (ZONE) Heavy Snow 0 2055154 18
1996-03-07 COASTAL YORK (ZONE) Heavy Snow 0 2055155 23
1996-03-07 INTERIOR YORK (ZONE) Heavy Snow 0 2055155 18
1996-04-09 INTERIOR YORK (ZONE) Heavy Snow 0 2054860 18
1996-04-09 COASTAL YORK (ZONE) Heavy Snow 0 2054860 23
1996-04-16 INTERIOR YORK (ZONE) Heavy Rain 0 2054862 18
1996-04-16 COASTAL YORK (ZONE) Heavy Rain 0 2054862 23
1996-04-16 INTERIOR YORK (ZONE) Flood 0 2054864 18
1996-04-16 COASTAL YORK (ZONE) Flood 820000 2054864 23
1996-04-16 COASTAL YORK (ZONE) Coastal Flood 0 2054863 23
1996-05-12 YORK CO. Flash Flood 0 2055784 31
1996-07-08 YORK CO. Hail 1.75 0 2055796 31
1996-07-08 YORK CO. Hail 1.75 0 2055797 31
1996-07-08 YORK CO. Hail 0.75 0 2055798 31
1996-07-08 YORK CO. Hail 1.5 0 2055799 31
1996-07-16 YORK CO. Thunderstorm Wind 0 2055810 31
1996-07-16 YORK CO. Thunderstorm Wind 0 2055811 31
1996-07-16 YORK CO. Thunderstorm Wind 0 2055812 31
... ... ... ... ... ... ...
2015-02-02 COASTAL YORK (ZONE) Heavy Snow 0 93914 23
2015-02-07 COASTAL YORK (ZONE) Heavy Snow 0 93904 23
2015-02-14 INTERIOR YORK (ZONE) Heavy Snow 0 93897 18
2015-02-14 COASTAL YORK (ZONE) Heavy Snow 0 93897 23
2015-02-15 COASTAL YORK (ZONE) Coastal Flood 5000 93118 23
2015-02-18 INTERIOR YORK (ZONE) Heavy Snow 0 93885 18
2015-04-20 COASTAL YORK (ZONE) Coastal Flood 125000 95443 23
2015-05-28 YORK CO. Thunderstorm Wind 50 0 96583 31
2015-05-28 YORK CO. Thunderstorm Wind 50 0 96583 31
2015-05-28 YORK CO. Thunderstorm Wind 50 0 96583 31
2015-06-23 YORK CO. Thunderstorm Wind 50 0 98095 31
2015-07-19 YORK CO. Hail 2.75 0 98969 31
2015-07-19 YORK CO. Hail 1 0 98969 31
2015-07-19 YORK CO. Thunderstorm Wind 50 0 98969 31
2015-07-19 YORK CO. Thunderstorm Wind 50 0 98969 31
2015-07-19 YORK CO. Thunderstorm Wind 50 0 98969 31
2015-08-04 YORK CO. Thunderstorm Wind 50 0 100161 31
2015-08-04 YORK CO. Hail 0.75 0 100161 31
2015-08-04 YORK CO. Hail 2 0 100161 31
2015-08-04 YORK CO. Hail 1.5 0 100161 31
2015-08-04 YORK CO. Hail 1 0 100161 31
2015-08-04 YORK CO. Hail 1.75 0 100161 31
2015-08-04 YORK CO. Hail 1 0 100161 31
2015-08-04 YORK CO. Hail 0.75 0 100161 31
2015-08-04 YORK CO. Hail 2.5 0 100161 31
2015-08-04 YORK CO. Hail 1 0 100161 31
2015-09-30 COASTAL YORK (ZONE) Coastal Flood 75000 100586 23
2015-10-29 COASTAL YORK (ZONE) Coastal Flood 2000 101799 23
2015-12-29 COASTAL YORK (ZONE) Heavy Snow 0 102612 23
2015-12-29 INTERIOR YORK (ZONE) Heavy Snow 0 102612 18

864 rows × 6 columns


In [305]:
##This error only started appearing on May 9, up until this point there were zero issues in this notebook... at a loss for words to explain

stormtotals = storms['EVENT_TYPE'].resample('M', how='count')
stormtotals.head()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-305-6e6f586c2697> in <module>()
      1 ##This error only started appearing on May 9, up until this point there were zero issues in this notebook... at a loss for words to explain
      2 
----> 3 stormtotals = storms['EVENT_TYPE'].resample('M', how='count')
      4 stormtotals.head()

//anaconda/lib/python3.5/site-packages/pandas/core/generic.py in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base)
   3944                      axis=axis, kind=kind, loffset=loffset,
   3945                      convention=convention,
-> 3946                      base=base)
   3947         return _maybe_process_deprecations(r,
   3948                                            how=how,

//anaconda/lib/python3.5/site-packages/pandas/tseries/resample.py in resample(obj, kind, **kwds)
    758     """ create a TimeGrouper and return our resampler """
    759     tg = TimeGrouper(**kwds)
--> 760     return tg._get_resampler(obj, kind=kind)
    761 resample.__doc__ = Resampler.__doc__
    762 

//anaconda/lib/python3.5/site-packages/pandas/tseries/resample.py in _get_resampler(self, obj, kind)
    859         raise TypeError("Only valid with DatetimeIndex, "
    860                         "TimedeltaIndex or PeriodIndex, "
--> 861                         "but got an instance of %r" % type(ax).__name__)
    862 
    863     def _get_grouper(self, obj):

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'

In [10]:
stormtotals


Out[10]:
BEGIN_DATE
1996-01-31    10
1996-02-29     1
1996-03-31     4
1996-04-30     7
1996-05-31     1
1996-06-30     0
1996-07-31     7
1996-08-31     0
1996-09-30     3
1996-10-31     6
1996-11-30     1
1996-12-31     1
1997-01-31     2
1997-02-28     0
1997-03-31     4
1997-04-30     2
1997-05-31     0
1997-06-30     0
1997-07-31     0
1997-08-31     3
1997-09-30     1
1997-10-31     0
1997-11-30     5
1997-12-31     3
1998-01-31    16
1998-02-28     1
1998-03-31     5
1998-04-30     0
1998-05-31     3
1998-06-30     9
              ..
2013-07-31     0
2013-08-31     2
2013-09-30     4
2013-10-31     5
2013-11-30     4
2013-12-31     4
2014-01-31     4
2014-02-28     6
2014-03-31     0
2014-04-30     0
2014-05-31     0
2014-06-30     0
2014-07-31     7
2014-08-31     4
2014-09-30     0
2014-10-31     0
2014-11-30     2
2014-12-31     0
2015-01-31     5
2015-02-28     7
2015-03-31     0
2015-04-30     1
2015-05-31     3
2015-06-30     1
2015-07-31     5
2015-08-31    10
2015-09-30     1
2015-10-31     1
2015-11-30     0
2015-12-31     2
Freq: M, dtype: int64

slicing data to create datasets of month-over-month comparisons:


In [30]:
jandata = ['1996-01-31','1997-01-31','1998-01-31','1999-01-31','2000-01-31','2001-01-31','2002-01-31','2003-01-31',
           '2004-01-31','2005-01-31','2006-01-31','2007-01-31','2008-01-31','2009-01-31','2010-01-31','2011-01-31',
          '2012-01-31','2013-01-31','2014-01-31','2015-01-31']
january=stormtotals[stormtotals.index.isin(jandata)]

In [32]:
febdata = ['1996-02-29','1997-02-28','1998-02-28','1999-02-28','2000-02-29','2001-02-28','2002-02-28','2003-02-28',
           '2004-02-29','2005-02-28','2006-02-28','2007-02-28','2008-02-29','2009-02-28','2010-02-28','2011-02-28',
          '2012-02-29','2013-02-28','2014-02-28','2015-02-28']
february=stormtotals[stormtotals.index.isin(febdata)]

In [33]:
mardata = ['1996-03-31','1997-03-31','1998-03-31','1999-03-31','2000-03-31','2001-03-31','2002-03-31','2003-03-31',
           '2004-03-31','2005-03-31','2006-03-31','2007-03-31','2008-03-31','2009-03-31','2010-03-31','2011-03-31',
          '2012-03-31','2013-03-31','2014-03-31','2015-03-31']
march=stormtotals[stormtotals.index.isin(mardata)]

In [34]:
aprdata = ['1996-04-30','1997-04-30','1998-04-30','1999-04-30','2000-04-30','2001-04-30','2002-04-30','2003-04-30',
           '2004-04-30','2005-04-30','2006-04-30','2007-04-30','2008-04-30','2009-04-30','2010-04-30','2011-04-30',
          '2012-04-30','2013-04-30','2014-04-30','2015-04-30']
april=stormtotals[stormtotals.index.isin(aprdata)]

In [35]:
maydata = ['1996-05-31','1997-05-31','1998-05-31','1999-05-31','2000-05-31','2001-05-31','2002-05-31','2003-05-31',
           '2004-05-31','2005-05-31','2006-05-31','2007-05-31','2008-05-31','2009-05-31','2010-05-31','2011-05-31',
          '2012-05-31','2013-05-31','2014-05-31','2015-05-31']
may=stormtotals[stormtotals.index.isin(maydata)]

In [36]:
jundata = ['1996-06-30','1997-06-30','1998-06-30','1999-06-30','2000-06-30','2001-06-30','2002-06-30','2003-06-30',
           '2004-06-30','2005-06-30','2006-06-30','2007-06-30','2008-06-30','2009-06-30','2010-06-30','2011-06-30',
          '2012-06-30','2013-06-30','2014-06-30','2015-06-30']
june=stormtotals[stormtotals.index.isin(jundata)]

In [37]:
juldata = ['1996-07-31','1997-07-31','1998-07-31','1999-07-31','2000-07-31','2001-07-31','2002-07-31','2003-07-31',
           '2004-07-31','2005-07-31','2006-07-31','2007-07-31','2008-07-31','2009-07-31','2010-07-31','2011-07-31',
          '2012-07-31','2013-07-31','2014-07-31','2015-07-31']
july=stormtotals[stormtotals.index.isin(juldata)]

In [51]:
augdata = ['1996-08-31','1997-08-31','1998-08-31','1999-08-31','2000-08-31','2001-08-31','2002-08-31','2003-08-31',
           '2004-08-31','2005-08-31','2006-08-31','2007-08-31','2008-08-31','2009-08-31','2010-08-31','2011-08-31',
          '2012-08-31','2013-08-31','2014-08-31','2015-08-31']
august=stormtotals[stormtotals.index.isin(augdata)]

In [39]:
sepdata = ['1996-09-30','1997-09-30','1998-09-30','1999-09-30','2000-09-30','2001-09-30','2002-09-30','2003-09-30',
           '2004-09-30','2005-09-30','2006-09-30','2007-09-30','2008-09-30','2009-09-30','2010-09-30','2011-09-30',
          '2012-09-30','2013-09-30','2014-09-30','2015-09-30']
september=stormtotals[stormtotals.index.isin(sepdata)]

In [40]:
octdata = ['1996-10-31','1997-10-31','1998-10-31','1999-10-31','2000-10-31','2001-10-31','2002-10-31','2003-10-31',
           '2004-10-31','2005-10-31','2006-10-31','2007-10-31','2008-10-31','2009-10-31','2010-10-31','2011-10-31',
          '2012-10-31','2013-10-31','2014-10-31','2015-10-31']
october=stormtotals[stormtotals.index.isin(octdata)]

In [41]:
novdata = ['1996-11-30','1997-11-30','1998-11-30','1999-11-30','2000-11-30','2001-11-30','2002-11-30','2003-11-30',
           '2004-11-30','2005-11-30','2006-11-30','2007-11-30','2008-11-30','2009-11-30','2010-11-30','2011-11-30',
          '2012-11-30','2013-11-30','2014-11-30','2015-11-30']
november=stormtotals[stormtotals.index.isin(novdata)]

In [254]:
decdata = ['1996-12-31','1997-12-31','1998-12-31','1999-12-31','2000-12-31','2001-12-31','2002-12-31','2003-12-31',
           '2004-12-31','2005-12-31','2006-12-31','2007-12-31','2008-12-31','2009-12-31','2010-12-31','2011-12-31',
          '2012-12-31','2013-12-31','2014-12-31','2015-12-31']
december=stormtotals[stormtotals.index.isin(decdata)]

In [55]:
november


Out[55]:
BEGIN_DATE
1996-11-30    1
1997-11-30    5
1998-11-30    1
1999-11-30    2
2000-11-30    2
2001-11-30    4
2002-11-30    4
2003-11-30    2
2004-11-30    6
2005-11-30    0
2006-11-30    0
2007-11-30    0
2008-11-30    1
2009-11-30    1
2010-11-30    2
2011-11-30    1
2012-11-30    0
2013-11-30    4
2014-11-30    2
2015-11-30    0
dtype: int64

In [16]:
stormtotals_y = stormtotals.resample('A', how='sum')
stormtotals_y


//anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:4: FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...).sum()
Out[16]:
BEGIN_DATE
1996-12-31    41
1997-12-31    20
1998-12-31    57
1999-12-31    63
2000-12-31    62
2001-12-31    75
2002-12-31    42
2003-12-31    28
2004-12-31    22
2005-12-31    43
2006-12-31    32
2007-12-31    78
2008-12-31    80
2009-12-31    30
2010-12-31    48
2011-12-31    32
2012-12-31    23
2013-12-31    29
2014-12-31    23
2015-12-31    36
Freq: A-DEC, dtype: int64

In [70]:
##Daily temperature readings:

temps = pd.read_excel('/Users/jamesalbright/Desktop/Daily Temps.xlsx')
temps.head()


Out[70]:
Month Day Year Temp
0 1 1 1995 32.2
1 1 2 1995 31.5
2 1 3 1995 23.9
3 1 4 1995 23.8
4 1 5 1995 12.9

In [71]:
print('Variable dtypes:\n', temps.dtypes, sep='')


Variable dtypes:
Month      int64
Day        int64
Year       int64
Temp     float64
dtype: object

In [72]:
temps['Date'] = pd.to_datetime(temps['Day'] + 100*temps['Month'] + 10000*temps['Year'], format="%Y%m%d")
temps.head()


Out[72]:
Month Day Year Temp Date
0 1 1 1995 32.2 1995-01-01
1 1 2 1995 31.5 1995-01-02
2 1 3 1995 23.9 1995-01-03
3 1 4 1995 23.8 1995-01-04
4 1 5 1995 12.9 1995-01-05

In [73]:
del temps['Month']

In [74]:
del temps['Day']

In [75]:
temps = temps.set_index('Date')

In [76]:
temps


Out[76]:
Year Temp
Date
1995-01-01 1995 32.2
1995-01-02 1995 31.5
1995-01-03 1995 23.9
1995-01-04 1995 23.8
1995-01-05 1995 12.9
1995-01-06 1995 20.1
1995-01-07 1995 33.1
1995-01-08 1995 25.0
1995-01-09 1995 22.4
1995-01-10 1995 14.6
1995-01-11 1995 2.9
1995-01-12 1995 9.4
1995-01-13 1995 30.8
1995-01-14 1995 35.5
1995-01-15 1995 43.5
1995-01-16 1995 49.8
1995-01-17 1995 47.3
1995-01-18 1995 34.6
1995-01-19 1995 32.4
1995-01-20 1995 34.2
1995-01-21 1995 39.6
1995-01-22 1995 35.5
1995-01-23 1995 32.0
1995-01-24 1995 28.1
1995-01-25 1995 26.8
1995-01-26 1995 24.4
1995-01-27 1995 17.9
1995-01-28 1995 14.7
1995-01-29 1995 20.9
1995-01-30 1995 27.2
... ... ...
2016-03-07 2016 32.4
2016-03-08 2016 35.8
2016-03-09 2016 47.7
2016-03-10 2016 56.7
2016-03-11 2016 44.2
2016-03-12 2016 39.0
2016-03-13 2016 50.0
2016-03-14 2016 37.8
2016-03-15 2016 39.3
2016-03-16 2016 44.3
2016-03-17 2016 46.8
2016-03-18 2016 43.9
2016-03-19 2016 32.3
2016-03-20 2016 28.1
2016-03-21 2016 30.8
2016-03-22 2016 35.2
2016-03-23 2016 43.8
2016-03-24 2016 33.5
2016-03-25 2016 29.9
2016-03-26 2016 36.0
2016-03-27 2016 36.3
2016-03-28 2016 37.6
2016-03-29 2016 42.0
2016-03-30 2016 38.5
2016-03-31 2016 52.2
2016-04-01 2016 55.7
2016-04-02 2016 49.7
2016-04-03 2016 35.0
2016-04-04 2016 22.1
2016-04-05 2016 23.5

7766 rows × 2 columns


In [79]:
del temps['Year']

In [80]:
temps.resample('M').mean()


Out[80]:
Temp
Date
1995-01-31 27.593548
1995-02-28 22.364286
1995-03-31 34.896774
1995-04-30 41.140000
1995-05-31 51.819355
1995-06-30 64.856667
1995-07-31 69.829032
1995-08-31 67.164516
1995-09-30 57.256667
1995-10-31 52.851613
1995-11-30 36.753333
1995-12-31 24.622581
1996-01-31 22.045161
1996-02-29 24.424138
1996-03-31 30.019355
1996-04-30 42.236667
1996-05-31 47.925806
1996-06-30 62.466667
1996-07-31 66.206452
1996-08-31 66.935484
1996-09-30 59.913333
1996-10-31 47.593548
1996-11-30 35.390000
1996-12-31 34.745161
1997-01-31 23.480645
1997-02-28 29.032143
1997-03-31 31.106452
1997-04-30 41.920000
1997-05-31 51.232258
1997-06-30 63.803333
... ...
2013-11-30 37.860000
2013-12-31 25.319355
2014-01-31 21.309677
2014-02-28 24.007143
2014-03-31 27.629032
2014-04-30 43.210000
2014-05-31 53.935484
2014-06-30 64.260000
2014-07-31 69.754839
2014-08-31 66.529032
2014-09-30 60.363333
2014-10-31 54.658065
2014-11-30 39.476667
2014-12-31 34.025806
2015-01-31 22.016129
2015-02-28 15.078571
2015-03-31 30.819355
2015-04-30 45.280000
2015-05-31 59.532258
2015-06-30 61.256667
2015-07-31 68.380645
2015-08-31 70.048387
2015-09-30 65.056667
2015-10-31 49.319355
2015-11-30 43.040000
2015-12-31 37.654839
2016-01-31 27.670968
2016-02-29 29.689655
2016-03-31 37.509677
2016-04-30 37.200000

256 rows × 1 columns


In [113]:
annual_temps=temps.resample('A').mean()

In [125]:
annual_temps


Out[125]:
Temp
Date
1995-12-31 46.078082
1996-12-31 45.049454
1997-12-31 45.904658
1998-12-31 47.442740
1999-12-31 48.066575
2000-12-31 46.556011
2001-12-31 47.652329
2002-12-31 45.391781
2003-12-31 44.947123
2004-12-31 45.840984
2005-12-31 46.648219
2006-12-31 48.890685
2007-12-31 46.091507
2008-12-31 45.993716
2009-12-31 45.975342
2010-12-31 49.246849
2011-12-31 48.093973
2012-12-31 49.377869
2013-12-31 47.215616
2014-12-31 46.724932
2015-12-31 47.485205
2016-12-31 31.954167

slicing data to create datasets of month-over-month comparisons:


In [84]:
jantdata = ['1996-01-31','1997-01-31','1998-01-31','1999-01-31','2000-01-31','2001-01-31','2002-01-31','2003-01-31',
           '2004-01-31','2005-01-31','2006-01-31','2007-01-31','2008-01-31','2009-01-31','2010-01-31','2011-01-31',
          '2012-01-31','2013-01-31','2014-01-31','2015-01-31']
jantemp=temps[temps.index.isin(jantdata)]

In [86]:
febtdata = ['1996-02-29','1997-02-28','1998-02-28','1999-02-28','2000-02-29','2001-02-28','2002-02-28','2003-02-28',
           '2004-02-29','2005-02-28','2006-02-28','2007-02-28','2008-02-29','2009-02-28','2010-02-28','2011-02-28',
          '2012-02-29','2013-02-28','2014-02-28','2015-02-28']
febtemp=temps[temps.index.isin(febtdata)]

In [87]:
martdata = ['1996-03-31','1997-03-31','1998-03-31','1999-03-31','2000-03-31','2001-03-31','2002-03-31','2003-03-31',
           '2004-03-31','2005-03-31','2006-03-31','2007-03-31','2008-03-31','2009-03-31','2010-03-31','2011-03-31',
          '2012-03-31','2013-03-31','2014-03-31','2015-03-31']
marchtemp=temps[temps.index.isin(martdata)]

In [270]:
aprtdata = ['1996-04-30','1997-04-30','1998-04-30','1999-04-30','2000-04-30','2001-04-30','2002-04-30','2003-04-30',
           '2004-04-30','2005-04-30','2006-04-30','2007-04-30','2008-04-30','2009-04-30','2010-04-30','2011-04-30',
          '2012-04-30','2013-04-30','2014-04-30','2015-04-30']
apriltemp=temps[temps.index.isin(aprtdata)]

In [89]:
maytdata = ['1996-05-31','1997-05-31','1998-05-31','1999-05-31','2000-05-31','2001-05-31','2002-05-31','2003-05-31',
           '2004-05-31','2005-05-31','2006-05-31','2007-05-31','2008-05-31','2009-05-31','2010-05-31','2011-05-31',
          '2012-05-31','2013-05-31','2014-05-31','2015-05-31']
maytemp=temps[temps.index.isin(maytdata)]

In [90]:
juntdata = ['1996-06-30','1997-06-30','1998-06-30','1999-06-30','2000-06-30','2001-06-30','2002-06-30','2003-06-30',
           '2004-06-30','2005-06-30','2006-06-30','2007-06-30','2008-06-30','2009-06-30','2010-06-30','2011-06-30',
          '2012-06-30','2013-06-30','2014-06-30','2015-06-30']
junetemp=temps[temps.index.isin(juntdata)]

In [91]:
jultdata = ['1996-07-31','1997-07-31','1998-07-31','1999-07-31','2000-07-31','2001-07-31','2002-07-31','2003-07-31',
           '2004-07-31','2005-07-31','2006-07-31','2007-07-31','2008-07-31','2009-07-31','2010-07-31','2011-07-31',
          '2012-07-31','2013-07-31','2014-07-31','2015-07-31']
julytemp=temps[temps.index.isin(jultdata)]

In [92]:
augtdata = ['1996-08-31','1997-08-31','1998-08-31','1999-08-31','2000-08-31','2001-08-31','2002-08-31','2003-08-31',
           '2004-08-31','2005-08-31','2006-08-31','2007-08-31','2008-08-31','2009-08-31','2010-08-31','2011-08-31',
          '2012-08-31','2013-08-31','2014-08-31','2015-08-31']
augusttemp=temps[temps.index.isin(augtdata)]

In [93]:
septdata = ['1996-09-30','1997-09-30','1998-09-30','1999-09-30','2000-09-30','2001-09-30','2002-09-30','2003-09-30',
           '2004-09-30','2005-09-30','2006-09-30','2007-09-30','2008-09-30','2009-09-30','2010-09-30','2011-09-30',
          '2012-09-30','2013-09-30','2014-09-30','2015-09-30']
septembertemp=temps[temps.index.isin(septdata)]

In [94]:
octtdata = ['1996-10-31','1997-10-31','1998-10-31','1999-10-31','2000-10-31','2001-10-31','2002-10-31','2003-10-31',
           '2004-10-31','2005-10-31','2006-10-31','2007-10-31','2008-10-31','2009-10-31','2010-10-31','2011-10-31',
          '2012-10-31','2013-10-31','2014-10-31','2015-10-31']
octobertemp=temps[temps.index.isin(octtdata)]

In [95]:
novtdata = ['1996-11-30','1997-11-30','1998-11-30','1999-11-30','2000-11-30','2001-11-30','2002-11-30','2003-11-30',
           '2004-11-30','2005-11-30','2006-11-30','2007-11-30','2008-11-30','2009-11-30','2010-11-30','2011-11-30',
          '2012-11-30','2013-11-30','2014-11-30','2015-11-30']
novembertemp=temps[temps.index.isin(novdata)]

In [284]:
dectdata = ['1996-12-31','1997-12-31','1998-12-31','1999-12-31','2000-12-31','2001-12-31','2002-12-31','2003-12-31',
           '2004-12-31','2005-12-31','2006-12-31','2007-12-31','2008-12-31','2009-12-31','2010-12-31','2011-12-31',
          '2012-12-31','2013-12-31','2014-12-31','2015-12-31']
decembertemp=temps[temps.index.isin(dectdata)]

charts comparing monthly average temperatures to the number of severe weather occurences. Do you notice any patterns or correlation?


In [263]:
plt.style.use('fivethirtyeight')

plt.figure(figsize=(20,10))
january.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('January Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

jantemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(0, 60)
plt.title('January Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[263]:
<matplotlib.text.Text at 0x13809c898>

In [265]:
plt.figure(figsize=(20,10))
february.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('February Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

febtemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(0, 60)
plt.title('February Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[265]:
<matplotlib.text.Text at 0x12cea2b38>

In [268]:
plt.figure(figsize=(20,10))
march.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('March Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

marchtemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('March Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[268]:
<matplotlib.text.Text at 0x133318e10>

In [286]:
plt.figure(figsize=(20,10))
april.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('April Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

apriltemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('April Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[286]:
<matplotlib.text.Text at 0x141558320>

In [272]:
plt.figure(figsize=(20,10))
may.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('May Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

maytemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('May Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[272]:
<matplotlib.text.Text at 0x139d8d668>

In [273]:
plt.figure(figsize=(20,10))
june.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('June Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

junetemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('June Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[273]:
<matplotlib.text.Text at 0x1381ca860>

In [274]:
plt.figure(figsize=(20,10))
july.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('July Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

julytemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('July Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[274]:
<matplotlib.text.Text at 0x137d3ef28>

In [275]:
plt.figure(figsize=(20,10))
august.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('August Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

augusttemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('August Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[275]:
<matplotlib.text.Text at 0x137ecb6a0>

In [276]:
plt.figure(figsize=(20,10))
september.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('September Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

septembertemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('September Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[276]:
<matplotlib.text.Text at 0x13402dc50>

In [277]:
plt.figure(figsize=(20,10))
october.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('October Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

octobertemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('October Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[277]:
<matplotlib.text.Text at 0x137ebd908>

In [278]:
plt.figure(figsize=(20,10))
november.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('November Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

novembertemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(20, 80)
plt.title('November Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[278]:
<matplotlib.text.Text at 0x132236668>

In [281]:
plt.figure(figsize=(20,10))
december.plot()
plt.xlim('1996', '2015') 
plt.ylim(0, 30) 
plt.title('December Severe Weather Occurences: 1996-2015', fontsize=18, loc='left')

decembertemp.plot(figsize=(20,10),color='red')
plt.xlim('1996', '2015') 
plt.ylim(0, 60)
plt.title('December Average Temperatures: 1996-2015', fontsize=18, loc='left')


Out[281]:
<matplotlib.text.Text at 0x1380772e8>

With data only available back to 1996, and without being able to confirm the veracity of severe weather recordings, unfortunately it is difficult to pull conclusive correlations between tempuerature fluctations and frequency of severe weather occurances in Souther Maine. Ideally, we would have liked to have used data going back a century or so. What is interesting, is that one can see some mirroring overall with respect to higher observed monthly average tempuratures being accompanied by a higher number of severe weather occurances.


In [ ]: