File size: 4,903 Bytes
a213b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8e6eed2a",
   "metadata": {},
   "source": [
    "# U.S. Tornado Catalog 1950–2024\n",
    "\n",
    "Starter notebook for the Kaggle dataset in this folder. It loads `tornadoes.csv` with pandas and walks through quality checks and a first piece of analysis.\n",
    "\n",
    "**Files:** `tornadoes.csv`, `data_dictionary.csv`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0000f7f2",
   "metadata": {},
   "source": [
    "## 1. Load the data"
   ]
  },
  {
   "cell_type": "code",
   "id": "fe2cc775",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv(\"tornadoes.csv\", low_memory=False)\n",
    "print(df.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "325de123",
   "metadata": {},
   "source": [
    "## 2. Shape, types and missing values"
   ]
  },
  {
   "cell_type": "code",
   "id": "6eb42bc8",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(f\"{df.shape[0]:,} rows x {df.shape[1]} columns\")\n",
    "\n",
    "missing = df.isna().mean().mul(100).sort_values(ascending=False)\n",
    "missing[missing > 0].round(1).to_frame(\"missing_%\").head(15)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2d963fe",
   "metadata": {},
   "source": [
    "## 3. Numeric summary"
   ]
  },
  {
   "cell_type": "code",
   "id": "aa2f8fd4",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.describe(include='number').T.round(2).head(20)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "950f8aaf",
   "metadata": {},
   "source": [
    "## 4. Tornadoes per year"
   ]
  },
  {
   "cell_type": "code",
   "id": "32a46f35",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.groupby(\"yr\").size().plot(figsize=(11, 4), title=\"Recorded tornadoes per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6959bcbb",
   "metadata": {},
   "source": [
    "## 5. Ratings"
   ]
  },
  {
   "cell_type": "code",
   "id": "429d7227",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df[\"magnitude_label\"].value_counts().head(14).to_frame(\"tornadoes\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8ea63fb",
   "metadata": {},
   "source": [
    "## 6. Where they happen\\n\\nTop 15 states by count."
   ]
  },
  {
   "cell_type": "code",
   "id": "2a8a2a95",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df[\"state_name\"].value_counts().head(15).to_frame(\"tornadoes\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91fcb8b2",
   "metadata": {},
   "source": [
    "## 7. Seasonality"
   ]
  },
  {
   "cell_type": "code",
   "id": "75238557",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df[\"month_name\"].value_counts().reindex([\n",
    "    \"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"]\n",
    ").plot(kind=\"bar\", figsize=(10, 4), title=\"Tornadoes by month\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1ae38cd",
   "metadata": {},
   "source": [
    "## 8. Casualties vs magnitude"
   ]
  },
  {
   "cell_type": "code",
   "id": "53e893cf",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.groupby(\"magnitude_label\")[[\"fat\", \"inj\"]].sum().sort_values(\"fat\", ascending=False).head(12)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f3cdddd",
   "metadata": {},
   "source": [
    "## 9. Path length by rating"
   ]
  },
  {
   "cell_type": "code",
   "id": "b609feb1",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.boxplot(column=\"len\", by=\"magnitude_label\", figsize=(11, 5), rot=45)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29677c56",
   "metadata": {},
   "source": [
    "## 10. F vs EF era"
   ]
  },
  {
   "cell_type": "code",
   "id": "3aadf186",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.groupby(\"scale\")[\"mag\"].agg([\"count\", \"mean\", \"median\"]).round(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e43770c",
   "metadata": {},
   "source": [
    "## Next steps\n",
    "\n",
    "See `KAGGLE.md` for analysis ideas, caveats and provenance."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11",
   "mimetype": "text/x-python",
   "file_extension": ".py",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}