DEV Community

Cover image for Automated Pitch Report Generator in Python: Trackman Data
Brett Hammit
Brett Hammit

Posted on • Edited on

Automated Pitch Report Generator in Python: Trackman Data

The times are changing in baseball and we are able to easily gather so much raw data and it can be pretty tedious to take the time to gather and clean and put it all together through excel sheets to make it into readable content for players to understand. I solved this by writing a script that packages this up and is easy to use for beginners who might have little to no experience in coding at all or a lot. The only thing necessary is following some instructions for software installation and following some straight forward directions. That being said let's jump right into it!

Table of Contents

  1. The Installation of Anaconda(Python) and Set Up
  2. Accessing the Script
  3. How to Work the Program

Chapter 1: Installing Anaconda and Set Up

For those of you who have not a whole lot of programming experience, but are interested in organizing your data this might be a bit tricky.

Step 1: Go to this link below and scroll all the way down to Anaconda Installers and select 64-Bit Graphical Installer for whichever operating system you have Windows, Mac or Linux. Select all the defaults and it might take a minute to get everything installed for you!
https://www.anaconda.com/products/individual

Step 2: Go into Anaconda either by clicking the desktop icon or in your launch pad for Mac users. (I know if this does not work you search "terminal" on your computer and type in that "anaconda-navigator". This should open it up.

Step 3: Launch JupyterLab and then click file on the top left, new and then notebook. Name this file whatever you may like.

Step 4: Last step and maybe the easiest in your documents go and create a new folder named "Pitch_Report". Finally you need to get the TrackMan data that you have in that messy csv and drag it into the sidebar below the cleaner. You're now set up and ready to get the script put in!

Alt Text
Your screen should look something like this with the cleaner and the csv file with your TrackMan data

Chapter 2: Accessing the Script

For this you can go to my GitHub link below and take the code and from Pitch_Reports take the code from Pitch_Report_Generator.ipynb and paste it into the file you made in JupyterLab. Now you should be ready to get into how the program works and how to run it.
https://github.com/BHam21/pitch-reports

Chapter 3: How the Program Works and Running it

The first bit of code is just importing the right libraries.

import pandas as pd
import numpy as np
Enter fullscreen mode Exit fullscreen mode

For this part of the code you are simply just enter the name of the CSV file of your TrackMan data between the apostrophes. This will change for each date and different csv file.

df=pd.read_csv('11_4_Scrimmage.csv', index_col=False)
Enter fullscreen mode Exit fullscreen mode

This next part of the code you don't have to worry about because it is just selecting and cleaning the data for you.

df=df[['Pitcher','TaggedPitchType','RelSpeed','SpinRate','SpinAxis','Extension','InducedVertBreak',
      'HorzBreak','VertApprAngle','pfxx','pfxz']]

#Rounding the decimals in the Data Frame
df=df.round(decimals=1)

Final_Report=df.groupby(['Pitcher','TaggedPitchType',]).mean()
Final_Report=Final_Report.round(decimals=1)
Enter fullscreen mode Exit fullscreen mode

This is the final part of the code and the one of two parts you need to interact with, the only thing you need to do is go into your files and where your Pitch_Report folder is click the folder once and go to the upper left and click "copy path" paste this in between the apostrophes in the code below. This should give a similar result of the code below, but with your username where it says "YourName".

Now the code is set up and the only thing you need to do from here on out is change the date of your file inside the code below where it is says "11_5_FinalReport.csv" if we were using the next days data you would change it to "11_6_FinalReport.csv"

Final_Report.to_csv(r'C:\Users\YourName\Documents\Pitch_Report\11_4_FinalReport.csv')
Enter fullscreen mode Exit fullscreen mode

Running the Program

Now that we have it all set up we can finally run the program. If your Trackman data is on the left side with your cleaner file and the name of your csv is where it should be at the beginning go ahead and click "File" save. After this click "Run" and then Run All Cells.

Now you should be able to go into your documents and where your Pitch_Report folder is there should be a cleaned, sorted and nice looking file with all your TrackMan pitching data!

Below is an example of what your Final Report should look like in your Pitch Report folder with it being sorted by each pitcher and their pitches that they threw from that day.

Pitch_Report

End

Thank you for taking the time to read this article and check out my work, for any questions message me on Twitter or wherever and I will try my best to help you out. Thanks again!

Top comments (0)