cmc/cleberg.net
My personal web garden & blog.
clone: git clone https://gitbay.org/cmc/cleberg.net.git
main: content/blog/2024-01-27-tableau-dashboard.org · raw
1#+date: [2024-01-27 Sat 00:00:00]
2#+title: Omaha Crime Data: 8 Years in Tableau
3#+description: Visualizing 8 years of Omaha crime data in Tableau.
4#+slug: tableau-dashboard
5#+filetags: :web:
6
7In this project, I am going to show you how to use Tableau Public for free to
8create simple dashboards.
9
10I will be creating simple visuals from an Omaha crime data set and combining
11them to create the dashboard below. You can view this dashboard interactively
12online here: [[https://public.tableau.com/app/profile/c.c7042/viz/OmahaCrimeData2015-2023/OmahaCrimeData2015-2023#1][Omaha Crime Data (2015 - 2023)]].
13
14#+caption: Tableau Dashboard
15#+attr_html: :alt A Tableau dashboard showing a map of Omaha with a dot for each crime, a bar chart with totals per crime category, and a line chart showing a timeline of crime totals by month.
16[[https://img.cleberg.net/blog/20240127-tableau-dashboard/dashboard.webp]]
17
18* Gather the Data
19
20You can download incident data from the Omaha Police Department on their
21[[https://police.cityofomaha.org/crime-information/incident-data-download][Incident Data Download]] page. They currently have files for the years 2015
22through 2023.
23
24Each file will be downloaded as a CSV file, approximately 3 MB - 8 MB.
25
26* Clean and Transform the Data
27
28I have used Python to combine the files into a single CSV file, as well as
29adding a custom =datetime= column. You could do this step in any software you
30prefer, but I prefer Python as its free, easy to use, and has a plethora of
31support resources online.
32
33Start by opening a terminal, navigating to your Downloads directory, and
34creating a python script.
35
36#+begin_src sh
37cd ~/Downloads
38nano data_processing.py
39#+end_src
40
41Within the Python script, paste the following:
42
43#+begin_src python
44# Import modules
45import pandas as pd
46import glob
47import os
48
49# Import the data
50path = r"~/Downloads/*.csv"
51files = glob.glob(path)
52
53list = []
54
55for file in files:
56 df_tmp = pd.read_csv(file)
57 li.append(df_tmp)
58
59df = pd.concat(list, axis=0, ignore_index=True)
60
61# Create a combined datetime column
62df["datetime"] = pd.to_datetime(
63 df["date"] + " " + df["time"],
64 format="%m/%d/%Y %H:%M:%S"
65)
66df.head()
67
68# Export the combined data
69df.to_csv(r"~/Downloads/combined_incidents.csv")
70#+end_src
71
72Once pasted, save and close the file. You can execute the file like so:
73
74#+begin_src sh
75python3 data_processing.py
76#+end_src
77
78After this, you should have a combined data file that contains all incidents
79between 2015 and 2023. Mine was approximately 55 MB.
80
81* Tableau Public
82
83[[https://public.tableau.com/][Tableau Public]] is a free-to-use web application that allows you to create
84visualizations by uploading data sources. Note that there's no way to keep the
85data and visualizations private, so don't upload anything private.
86
87After creating an account, you can click the =Create= > =Web Authoring= link to
88create your first visualization.
89
90** Upload the Data
91
92Once you've opened your first project, Tableau will ask you to connect to your
93data. For this project, click the =Upload from computer= button and select the
94CSV file previously combined in the step above.
95
96Once connected, you can refresh the preview of the data with the =Refresh Data
97Source= button in the toolbar.
98
99If you need to edit any of the data types, column names, etc., you can do so
100now. Once complete, generate an extract so that you can start creating
101visualizations.
102
103** Create Visualizations
104
105To start, create a worksheet in the toolbar at the bottom of the screen.
106
107Within this screen, select a column from the =Data= side bar on the left and
108drag it into the =Columns= or =Rows= area of the canvas.
109
110See below for the map visualization. You can recreate this by adding the
111following fields:
112
113- =Columns=: Lon
114- =Rows=: Lat
115- =Marks=:
116 - Description
117 - Datetime
118- =Filters=: Datetime
119
120You can repeat this process for each visualization you want to create. Explore
121your options by dragging data fields to different areas and by opening the field
122options to explore what operations can be performed on different data types
123(e.g., average, count, etc.).
124
125** Create Dashboard
126
127To create a dashboard, click the button on the toolbar at the bottom of the
128screen. Within the dashboard, drag each sheet from the left side bar onto the
129dashboard canvas.
130
131** Formatting
132
133You can explore a ton of different formatting options throughout the worksheets
134and dashboard. Specifically for maps, you can alter the map layers, background,
135and visible features through the =Map= menu in the top file menu of the editing
136screen.
137
138In the finished dashboard below, I opted for a dark mode with a map that showed
139county lines and city names.
140
141There's a ton of other options available to be used in a dashboard like this,
142but this project shows a quick preview of what you can do in Tableau Public.
143
144#+caption: Tableau Dashboard
145#+attr_html: :alt A Tableau dashboard showing a map of Omaha with a dot for each crime, a bar chart with totals per crime category, and a line chart showing a timeline of crime totals by month.
146[[https://img.cleberg.net/blog/20240127-tableau-dashboard/dashboard.webp]]