In [2]:
## import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

#allows us to show plots in notebook
%matplotlib inline

In [7]:
filename = '' #created a variable that it would be easy to call

sheef = pd.read_csv(filename, sep = '\s+', header=1, index_col='Date')
#made dataframe into variable sheef, deleted unnecessary header, changed the index
sheef


Out[7]:
MW Longitude Latitude Source Depth DF OM OMT MW2
Date
162701010000 3.4 -70.800 42.600 NCE 0.00 3.8 MbLg 3.37 NaN
163806111900 6.5 -71.800 44.400 Ebe 0.00 6.5 MbLg 6.46 NaN
163807010000 2.4 -70.900 42.500 NCE 0.00 2.7 MbLg 2.36 NaN
163901250000 2.4 -70.950 42.500 NCE 0.00 2.7 MbLg 2.36 NaN
164303151200 2.9 -70.800 42.800 NCE 0.00 3.3 MbLg 2.90 NaN
164306111800 2.9 -70.800 42.800 NCE 0.00 3.3 MbLg 2.90 NaN
165311080000 2.4 -70.900 42.600 NCE 0.00 2.7 MbLg 2.36 NaN
165804140000 3.1 -70.900 42.500 NCE 0.00 3.5 MbLg 3.08 NaN
166102101200 5.3 -73.000 45.500 GSC 0.00 5.7 ML 5.29 NaN
166302051730 7.0 -70.100 47.600 GSC 0.00 7.0 Mw 7.00 NaN
166302052300 4.0 -70.100 47.600 GSC 0.00 4.4 ML 3.99 NaN
166302061500 4.6 -70.100 47.600 GSC 0.00 5.0 ML 4.59 NaN
166302071400 3.3 -70.100 47.600 GSC 0.00 3.7 ML 3.29 NaN
166311160000 3.3 -70.100 47.600 GSC 0.00 3.7 ML 3.29 NaN
166400000000 3.3 -70.100 47.600 GSC 0.00 3.7 ML 3.29 NaN
166502240000 5.1 -70.000 47.800 GSC 0.00 5.5 ML 5.09 NaN
166510152150 3.3 -71.220 46.820 GSC 0.00 3.7 ML 3.29 NaN
166804030900 2.9 -71.100 42.350 NCE 0.00 3.3 MbLg 2.90 NaN
166804131300 4.6 -70.500 47.100 GSC 0.00 5.0 ML 4.59 NaN
166812190000 3.1 -71.500 42.500 Ebe 0.00 3.5 MbLg 3.08 NaN
167202000000 3.3 -69.700 48.150 GSC 0.00 3.7 ML 3.29 NaN
167312080000 2.6 -69.700 48.150 GSC 0.00 3.0 ML 2.59 NaN
167712130000 2.9 -73.500 41.100 NCE 0.00 3.3 MbLg 2.90 NaN
168502182100 3.1 -70.800 42.800 Ebe 0.00 3.5 MbLg 3.08 NaN
169702201115 2.6 -70.800 42.000 Ebe 0.00 3.0 MbLg 2.63 NaN
169801010000 2.9 -73.470 41.380 NCE 0.00 3.3 MbLg 2.90 NaN
170001270500 9.0 -125.000 48.500 GSC 9.00 OT 9.00 NaN NaN
170102100000 2.4 -70.950 42.600 NCE 0.00 2.7 MbLg 2.36 NaN
170103080000 2.4 -70.950 42.600 NCE 0.00 2.7 MbLg 2.36 NaN
170201010000 2.9 -73.500 41.400 NCE 0.00 3.3 MbLg 2.90 NaN
... ... ... ... ... ... ... ... ... ...
201012231238 3.7 -130.268 50.437 PGC 10.00 F 3.7 Mw 3.70
201012231247 3.7 -130.236 50.467 PGC 10.00 F 3.7 Mw 3.70
201012232047 3.4 -130.135 50.434 PGC 10.00 F 3.4 Mw 3.40
201012240307 2.1 -109.200 75.530 GSC 18.00 F 2.6 MN 2.07
201012241416 2.2 -67.615 49.307 GSC 1.00 F 2.7 MN 2.17
201012260434 3.4 -108.880 76.272 GSC 18.00 F 3.9 MN 3.37
201012261944 2.8 -94.326 74.006 GSC 18.00 F 3.3 MN 2.77
201012270439 2.8 -96.447 67.083 GSC 18.00 F 3.3 MN 2.77
201012270448 2.2 -108.956 76.216 GSC 18.00 F 2.7 ML 2.17
201012271500 2.7 -137.874 58.346 PGC 21.01 2.7 ML 2.70 NaN
201012271608 2.6 -75.311 45.745 GSC 15.29 3.1 MN 2.57 NaN
201012271653 3.0 -137.482 58.588 PGC 24.09 3.0 ML 3.00 NaN
201012271708 2.4 -71.100 70.810 GSC 18.00 F 2.9 MN 2.37
201012281123 2.9 -130.145 50.280 PGC 10.00 F 2.9 Mw 2.90
201012281157 3.2 -130.426 50.311 PGC 10.00 F 3.2 Mw 3.20
201012281217 2.4 -57.508 42.180 GSC 18.00 F 2.9 ML 2.37
201012281238 3.4 -130.489 50.661 PGC 10.00 F 3.4 Mw 3.40
201012281634 2.8 -88.016 64.924 GSC 18.00 F 3.3 MN 2.77
201012281857 3.4 -70.859 73.283 GSC 18.00 F 3.9 ML 3.37
201012282224 3.2 -133.513 65.229 PGC 1.00 F 3.2 ML 3.20
201012290055 3.6 -130.197 50.538 PGC 10.00 F 3.6 Mw 3.60
201012291415 2.7 -114.560 79.362 GSC 18.00 F 3.2 ML 2.67
201012300038 2.0 -72.724 49.482 GSC 18.00 F 2.5 MN 1.97
201012300149 4.0 -133.442 65.218 PGC 5.00 F 4.0 Mw 4.00
201012300622 3.0 -130.282 50.599 PGC 10.00 F 3.0 Mw 3.00
201012301255 3.8 -85.890 40.430 PDE 4.00 3.8 Mw 3.80 NaN
201012301823 3.0 -134.842 54.928 PGC 20.00 F 3.0 ML 3.00
201012301921 5.0 -156.149 56.748 PDE 54.00 5.0 Mw 5.00 NaN
201012310601 2.9 -53.568 69.760 GSC 18.00 F 3.4 ML 2.87
201012310949 3.8 -130.755 50.952 PGC 10.00 F 3.8 Mw 3.80

41690 rows × 9 columns


In [122]:
sheef['decade'] = sheef['year'] // 10*10

# plot the magnitude of earthquakes over time
plt.bar (sheef.Depth, sheef.MW)

#plotted MW column


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-122-571fca12c1f4> in <module>()
----> 1 sheef['decade'] = sheef['year'] // 10*10
      2 
      3 # plot the magnitude of earthquakes over time
      4 plt.bar (sheef.Depth, sheef.MW)
      5 

/Users/Jessi/anaconda/lib/python3.4/site-packages/pandas/core/frame.py in __getitem__(self, key)
   1795             return self._getitem_multilevel(key)
   1796         else:
-> 1797             return self._getitem_column(key)
   1798 
   1799     def _getitem_column(self, key):

/Users/Jessi/anaconda/lib/python3.4/site-packages/pandas/core/frame.py in _getitem_column(self, key)
   1802         # get column
   1803         if self.columns.is_unique:
-> 1804             return self._get_item_cache(key)
   1805 
   1806         # duplicate columns & possible reduce dimensionaility

/Users/Jessi/anaconda/lib/python3.4/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
   1082         res = cache.get(item)
   1083         if res is None:
-> 1084             values = self._data.get(item)
   1085             res = self._box_item_values(item, values)
   1086             cache[item] = res

/Users/Jessi/anaconda/lib/python3.4/site-packages/pandas/core/internals.py in get(self, item, fastpath)
   2849 
   2850             if not isnull(item):
-> 2851                 loc = self.items.get_loc(item)
   2852             else:
   2853                 indexer = np.arange(len(self.items))[isnull(self.items)]

/Users/Jessi/anaconda/lib/python3.4/site-packages/pandas/core/index.py in get_loc(self, key, method)
   1570         """
   1571         if method is None:
-> 1572             return self._engine.get_loc(_values_from_object(key))
   1573 
   1574         indexer = self.get_indexer([key], method=method)

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3824)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3704)()

pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12280)()

pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12231)()

KeyError: 'year'

In [1]:
#make biger figure
plt.figure(figsize=(10,8))

#plot the depth of earthquakes over time
sheef['Depth'].plot(cmap=plt.cm.cool)

#add labels
plt.ylabel('Depth')
plt.title ('The depth of earthquakes between 1627 and 2010')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-0a5c5ef512d2> in <module>()
      1 #make biger figure
----> 2 plt.figure(figsize=(10,8))
      3 
      4 #plot the depth of earthquakes over time
      5 sheef['Depth'].plot(cmap=plt.cm.cool)

NameError: name 'plt' is not defined

In [129]:
#make bigger figure
plt.figure(figsize=(10,8))

#plot the magnitude of earthquakes over time
sheef['MW'].plot(cmap=plt.cm.autumn)

#add labels
plt.ylabel ('Magnitude')
plt.title ('Magnitude of Earthquakes between 1627 and 2010')


Out[129]:
<matplotlib.text.Text at 0x16b74e128>

In [49]:
#scatter plot of the magnitude of earthquakes to see the distribution
plt.figure(figsize=(10,8))

#set two variables for date (index) and magnitude
x=[sheef.index]
y=[sheef.MW]

#plot variables
plt.scatter(x, y, s=50, cmap=plt.cm.cool)
plt.show()


  • why you chose to visualize the data with the plots you chose * what new thing you learned about your data from the visualization

I chose to visualize the Magnitude with a regular plot because it clearly displayed the range of magnitudes, and a general change over time.

I chose the scatter plot because I thought it clearly displayed the variety of data, and the individual earthquakes clearer than the general plot did.

I thought a bar graph would be a good representation of the depth of the earthquakes, but I couldn't get it to work so I guess it isn't representing it very well. I changed this to a regular plot so there was an actual visual. This shows the different depths almost as well.

I learned that there was more data collected closer to our year, and that there was more earthquakes with a higher magnitude and much greater depth than in previous years. This indicates more seismic activity in recent years.


In [ ]:


In [ ]: