content/blog/2024-01-27-tableau-dashboard.org

0b2895a90c7751ce06e4b26d4db41005ea2f40a9
cleberg.net/content/blog/2024-01-27-tableau-dashboard.org rendered · source · history · blame · raw

144 lines · 4899 bytes

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