{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"connection = sqlite3.connect('Proj2earfquak/index.sqlite')\n",
"cursor = connection.cursor()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cursor.execute(\"SELECT * FROM Earthquakes;\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"table = pd.read_sql_query(\"SELECT * from Earthquakes\", connection)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 1 and Part 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"placecounts = dict(table.place.value_counts(normalize=False))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"regioncounts = dict(table.region.value_counts(normalize=False))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"How many earthquake locations to show?20\n",
"\n",
"Top 20 earthquake places\n",
"Central California 417\n",
"Bonin Islands, Japan region 404\n",
"Albania 382\n",
"Northern California 375\n",
"Andreanof Islands, Aleutian Islands, Alaska 319\n",
"New Britain region, Papua New Guinea 277\n",
"Mount St. Helens area, Washington 259\n",
"Vanuatu 235\n",
"Fiji region 213\n",
"Hindu Kush region, Afghanistan 197\n",
"Taiwan region 149\n",
"Aegean Sea 141\n",
"Tonga 133\n",
"Czech Republic 128\n",
"France 123\n",
"northern Italy 115\n",
"offshore Northern California 99\n",
"Greece 96\n",
"southwestern Ryukyu Islands, Japan 95\n",
"south of the Fiji Islands 90\n",
"\n",
"Top 20 earthquake regions\n",
"California 1488\n",
"Japan 891\n",
"Alaska 666\n",
"Indonesia 604\n",
"Mexico 570\n",
"Papua New Guinea 477\n",
"Albania 382\n",
"Washington 340\n",
"Figi 311\n",
"Chile 249\n",
"Vanuatu 245\n",
"Greece 220\n",
"Afghanistan 202\n",
"Taiwan 198\n",
"Tonga 156\n",
"Italy 155\n",
"Philippines 154\n",
"Aegean Sea 141\n",
"France 139\n",
"Czech Republic 132\n"
]
}
],
"source": [
"howmany = int(input(\"How many earthquake locations to show?\"))\n",
"print ('\\nTop', howmany, 'earthquake places')\n",
"\n",
"x = sorted(placecounts, key=placecounts.get, reverse=True)\n",
"for k in x[:howmany]:\n",
" print(k, placecounts[k])\n",
" if placecounts[k] < 10 : break\n",
"\n",
"print('\\nTop',howmany,'earthquake regions')\n",
"x = sorted(regioncounts, key=regioncounts.get, reverse=True)\n",
"for k in x[:howmany]:\n",
" print(k, regioncounts[k])\n",
" if regioncounts[k] < 10 : break\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Basic Statistics\n"
]
}
],
"source": [
"print(\"\\nBasic Statistics\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Place that has the most earthquakes: Central California\n",
"Region that has the most earthquakes: California\n"
]
}
],
"source": [
"print (\"Place that has the most earthquakes: \", sorted(placecounts, key=placecounts.get, reverse=True)[0])\n",
"print (\"Region that has the most earthquakes: \", sorted(regioncounts, key=regioncounts.get, reverse=True)[0])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
"\n",
"\n",
" | \n",
"id | \n",
"magnitude | \n",
"time | \n",
"depth | \n",
"place | \n",
"title | \n",
"felt | \n",
"region | \n",
"
\n",
"\n",
"\n",
"\n",
"0 | \n",
"usp0002upb | \n",
"4.70 | \n",
"518050385280 | \n",
"33.000 | \n",
"Tonga | \n",
"M 4.7 - Tonga | \n",
"None | \n",
"Tonga | \n",
"
\n",
"\n",
"1 | \n",
"usp0002upa | \n",
"4.50 | \n",
"518050075320 | \n",
"33.000 | \n",
"central Peru | \n",
"M 4.5 - central Peru | \n",
"None | \n",
"Peru | \n",
"
\n",
"\n",
"2 | \n",
"usp0002up9 | \n",
"4.20 | \n",
"518048545920 | \n",
"10.000 | \n",
"north of Svalbard | \n",
"M 4.2 - north of Svalbard | \n",
"None | \n",
"Svalbard | \n",
"
\n",
"\n",
"3 | \n",
"ci125844 | \n",
"2.55 | \n",
"518047684570 | \n",
"5.738 | \n",
"35km ESE of San Clemente Is. (SE tip), CA | \n",
"M 2.6 - 35km ESE of San Clemente Is. (SE tip), CA | \n",
"None | \n",
"California | \n",
"
\n",
"\n",
"4 | \n",
"usp0002up8 | \n",
"4.70 | \n",
"518046364120 | \n",
"33.000 | \n",
"Hindu Kush region, Afghanistan | \n",
"M 4.7 - Hindu Kush region, Afghanistan | \n",
"None | \n",
"Afghanistan | \n",
"
\n",
"\n",
"
\n",
"
"
],
"text/plain": [
" id magnitude time depth \\\n",
"0 usp0002upb 4.70 518050385280 33.000 \n",
"1 usp0002upa 4.50 518050075320 33.000 \n",
"2 usp0002up9 4.20 518048545920 10.000 \n",
"3 ci125844 2.55 518047684570 5.738 \n",
"4 usp0002up8 4.70 518046364120 33.000 \n",
"\n",
" place \\\n",
"0 Tonga \n",
"1 central Peru \n",
"2 north of Svalbard \n",
"3 35km ESE of San Clemente Is. (SE tip), CA \n",
"4 Hindu Kush region, Afghanistan \n",
"\n",
" title felt region \n",
"0 M 4.7 - Tonga None Tonga \n",
"1 M 4.5 - central Peru None Peru \n",
"2 M 4.2 - north of Svalbard None Svalbard \n",
"3 M 2.6 - 35km ESE of San Clemente Is. (SE tip), CA None California \n",
"4 M 4.7 - Hindu Kush region, Afghanistan None Afghanistan "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"felt = np.array(table.felt)\n",
"depth = np.array(table.depth)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"magnitude = np.array(table.magnitude)\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"feltMagnitude = magnitude[depth > 50]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of felt earthquakes: 2162\n"
]
}
],
"source": [
"print (\"Number of felt earthquakes: \", feltMagnitude.shape[0])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mean felt earthquake: 4.709532839962996\n"
]
}
],
"source": [
"print (\"Mean felt earthquake: \", np.mean(feltMagnitude))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Biggest Earthquake, 7.4\n"
]
}
],
"source": [
"print (\"Biggest Earthquake, \", max(feltMagnitude))"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"import seaborn as sns\n",
"sns.set()\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"placecountsdf = pd.DataFrame().from_records([\n",
" {\n",
" 'place': key,\n",
" 'count': placecounts[key]\n",
" } for key in placecounts\n",
"])"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"image/png":...