In this blog series, I’ll delve into the exciting world of web development as I embark on the creation of GECACS (Guild Equipment Check-out and Control System) for the Fredericksburg Spinners and Weavers Guild. I have never developed a web application before, so I’m going to use ChatGPT 3.5 to guild me through the process.
Many years ago I elected to use the Forminator plug-in to create a check-out form for our guild members to use when they wanted to check-out equipment. The problem is that there was no way for the member or librarian to document the equipment had been turned back in. Trying to associate the check-out form with a check-in was becoming difficult for our librarian to keep up with. Since I am the guild’s “technology officer” and with my data science background, it seamed like a natural option to develop a solutions that would showcase my current skills and help me develop new ones.
Univariate analysis is a crucial step in data analysis that focuses on examining and summarizing the characteristics of a single variable or attribute from the dataset. Univariate analysis provides a foundation for understanding the characteristics of individual variables, which is essential for more advanced multivariate analyses and modeling. It helps identify patterns, outliers, and potential data quality issues, making it a crucial step in the data analysis pipeline.
Python
import pandas as pd# import and store the datasetqbs = pd.read_excel("https://myordinaryjourney.com/wp-content/uploads/2023/09/cleaned_qbs.xlsx")print(qbs.head())#Output Player Total 20092010201120122013201420152016...\0 A.Dalton 2500411501...1 A.Luck 1700053411...2 A.Rodgers 4133352254...3 A.Smith 2311111641...4 B.Bortles 1200000121...2023 Games Per Game Attempts Per 100 Att Sacked Per Sack \001700.1555570.453610.06910940.1836200.471860.091202280.1878400.525420.076301490.1546480.493670.06340790.1527190.442010.060 Sack Per Att Third Down % qboc 00.06540.00010.05129.41020.06939.02030.07926.09040.07433.330
First, we should look to see what the variable datatypes are and if there are any null or missing values.
Python
qbs.info(verbose=True)#Output<class'pandas.core.frame.DataFrame'>RangeIndex:66 entries,0 to 65Data columns (total 26 columns):# Column Non-Null Count Dtype ----------------------------0 Player 66 non-null object1 Total 66 non-null int64 2200966 non-null int64 3201066 non-null int64 4201166 non-null int64 5201266 non-null int64 6201366 non-null int64 7201466 non-null int64 8201566 non-null int64 9201666 non-null int64 10201766 non-null int64 11201866 non-null int64 12201966 non-null int64 13202066 non-null int64 14202166 non-null int64 15202266 non-null int64 16202366 non-null int64 17 Games 66 non-null int64 18 Per Game 66 non-null float6419 Attempts 66 non-null int64 20 Per 100 Att 66 non-null float6421 Sacked 66 non-null int64 22 Per Sack 66 non-null float6423 Sack Per Att 66 non-null float6424 Third Down %66 non-null float6425 qboc 66 non-null int64 dtypes: float64(5), int64(20),object(1)
The variables I will examine more closely are the total number of Roughing the Passer (RTP) calls per quarterback, the number of RTP calls per year for each quarterback, and the number of RTP calls per games played for their distribution, central tendency, and variance. I will be using Python and Jupyter Notebooks.
Python
table_stats = qbs.describe()print(table_stats)#Output Total 20092010201120122013\count 66.00000066.00000066.00000066.00000066.00000066.000000mean 18.0909090.6969700.8333331.1212121.2575761.075758std 12.5056631.1763011.4526721.7673551.7742661.825550min2.0000000.0000000.0000000.0000000.0000000.00000025%8.2500000.0000000.0000000.0000000.0000000.00000050%15.5000000.0000000.0000000.0000000.0000000.00000075%24.7500001.0000001.0000002.0000002.0000001.000000max57.0000005.0000006.0000008.0000006.0000008.0000002014201520162017...2023 Games \count 66.00000066.00000066.00000066.00000...66.00000066.000000mean 1.3333331.4545451.2878791.30303...0.03030399.530303std 1.8425181.8328781.6985531.75385...0.17273353.915952min0.0000000.0000000.0000000.00000...0.00000042.00000025%0.0000000.0000000.0000000.00000...0.00000061.25000050%0.5000001.0000001.0000000.00000...0.00000077.50000075%2.0000002.0000002.0000002.00000...0.000000138.000000max7.0000007.0000006.0000007.00000...1.000000253.000000 Per Game Attempts Per 100 Att Sacked Per Sack \count 66.00000066.00000066.00000066.00000066.000000mean 0.1768183250.3030300.573636211.2121210.083424std 0.0738012085.2503480.241951117.9105940.034212min0.050000289.0000000.13000026.0000000.02400025%0.1125001794.5000000.390000131.5000000.05850050%0.1650002315.5000000.550000170.0000000.07800075%0.2200004476.0000000.740000264.5000000.107250max0.3500009725.0000001.240000542.0000000.202000 Sack Per Att Third Down % qboc count 66.00000066.00000066.000000mean 0.07009131.1437880.272727std 0.01644913.8728130.448775min0.0300000.0000000.00000025%0.05800025.0000000.00000050%0.06900030.7700000.00000075%0.08350039.7550001.000000max0.10300077.7800001.000000[8 rows x 25 columns]
Well, that was easy. Using the .describe() function allows for the examination of the data set’s values for central tendency (mean in this case) and the spread (standard deviation) and dispersion (technically). Although all the information is present to observe the dispersion of the information, it may hard to conceptualize the shape without using a visualization help. Histograms can aid in our observations.
Python
qbs.hist(figsize=(10,15))
Adjust the figure size to be able to view all the histogram outputs more clearly. The distributions for Per Game and Per 100 Attempts look nearly normal, so that will allow us to use some parametric tests for analysis.
Another visual that is helpful to see the distribution is a boxplot (box-and whisker plot). This time let us just look at just the Per Game and Per 100 Attempts.
The wonderful thing about boxplots is that they make it easy to identify outliers – observations that are outside the whiskers (either top or bottom). You can also easily see the centrality and spread of the data.
One additional variable that we should look at is the ‘qboc’. Did you notice that there was an interesting distribution when the histograms plotted above? Let’s take a closer look.
Python
qbs['qboc'].hist(figsize=(10,15))
As you can see there are only two values for this variable. And this makes sense since we are categorizing the quarterbacks based on if they are (1) or are not (0) a quarterback of color. I am going to do a bit of foreshadowing, but this means that if we wanted to do any sort of predictive analysis, we need to think about some additional models beyond regular linear regression, logistic regression to be specific… but that is a post for another day. For now, I have identified the variables we can use for some multivariate analysis:
Per Game
Per 100 Attempts
qboc
In this data exploration process, univariate analysis was applied to understand and summarize the characteristics of individual variables, specifically focusing on those related to Roughing the Passer (RTP) calls. The dataset was examined using Python and Jupyter Notebooks. The summary statistics and visualizations were generated to gain insights into the central tendency, dispersion, and distribution of the data.
The analysis revealed that variables such as “Per Game” and “Per 100 Attempts” exhibited nearly normal distributions, making them suitable for parametric tests. Additionally, the “qboc” variable, which categorizes quarterbacks based on their ethnicity, showed a binary distribution, indicating potential utility in predictive modeling.
This initial exploration sets the stage for further multivariate analysis and modeling, offering a foundation for more in-depth investigations into the relationships between these variables and RTP calls in NFL quarterbacks.
When working on a project that requires data, it is essential to consider the various sources and formats in which the information may be available. Often, the desired data cannot be found in one single location, requiring careful compilation from multiple sources. This process can be time-consuming and challenging, as each source may present its own set of complications and intricacies.
While some data may be readily accessible through online databases, APIs, or official government reports, it may not always be presented in the most convenient or usable form. For instance, a dataset could be in a raw, unstructured format, making it difficult to analyze and extract meaningful insights. In such cases, data manipulation techniques are necessary to transform the data into a suitable format.
Data manipulation involves various tasks such as cleaning, merging, and reshaping the data. Cleaning the data involves removing any inconsistencies, errors, or missing values. This step ensures that the data is accurate and reliable for analysis. Merging data from multiple sources requires aligning and combining different datasets based on common attributes or keys. This consolidation allows for a comprehensive and holistic view of the data.
Reshaping the data involves rearranging its structure to fit the desired analysis or visualization needs. This can include tasks such as pivoting, aggregating, or disaggregating the data. By reshaping the data, researchers and analysts can uncover patterns, trends, and relationships that might otherwise go unnoticed.
In the given scenario, the QB Penalty Stats table lacked information on the racial background of the players. While this data may not be readily available in the original source, alternative sources can be explored. In this case, a reliable and well-sourced list of black quarterbacks could be found on Wikipedia. Although caution is advisable when using information from Wikipedia, the aforementioned table demonstrates reliability in this particular case.
Working with data often goes beyond simply retrieving information from a single source. It requires diligent gathering, cleaning, merging, and reshaping of data to ensure accuracy and usability. With the right techniques and approaches, researchers can unlock the full potential of data and derive valuable insights.
Embarking on an Epic Journey
I now have a list of all QBs from 2009 until present (that’s 2023 for those of you that stumble upon my ramblings in the future) in the qb_rtp table. I also have a list of black QBs in the qbs_oc table. Sometimes I find it can be faster to do some of the data cleaning work in the native application. In this case, I needed to create a column in the black_qbs table that I could use to compare the qb_rtp[‘Player’] column in the other table. Luckily Excel’s autofill feature made this particularly easy. I inserted a blank column next to the [‘Quarterback’] called [‘short_name’]. After typing a few examples, I selected the “Autofill” option in the Data drop down menu, and voilà, I had the new column that I can use for comparison.
Starting to Use Notebooks
I haven’t used a Jupyter Notebook to code in a very long time. I usually use the Spyder IDE as I can see all my variables’ values at the same time. But I’m going to give it a shot. You can get the entire notebook here. The first step is to import the different libraries that I think I’ll need.
Make sure to verify the data has been loaded by viewing a few rows from each dataframe. If you are wondering what the ‘\n’ means, it is the regular expression for a new line. It creates some extra space between the table headings and the table data to make them more readable. Dataquest has a great quick guide and cheat sheet available here.
print('Quarterback Stats table:\n', qbs.head(),'\n')print('Quarterback of Color table:\n', qbs_oc.head())#OutputQuarterback Stats table: Player Total 20092010201120122013201420152016...\0 A.Dalton 2500411501...1 A.Luck 1700053411...2 A.Rodgers 4133352254...3 A.Smith 2311111641...4 B.Bortles 1200000121...20222023 Games Per Game Attempts Per 100 Att Sacked Per Sack \0201700.1555570.453610.069100940.1836200.471860.0912302280.1878400.525420.0763001490.1546480.493670.063400790.1527190.442010.060 Sack Per Att Third Down %00.06540.0010.05129.4120.06939.0230.07926.0940.07433.33[5 rows x 25 columns]Quarterback of Color table: Quarterback short_name Years active \0 Fritz Pollard F.Pollard 1920–19261 Joe Lillard J.Lillard 1932–19332 George Taliaferro G.Taliaferro 1950–19553 Marlin Briscoe M.Briscoe 1968*4 James Harris J.Harris 1969–1981 Team 0 Akron Pros, Milwaukee Badgers, Hammond Pros, P...1 Chicago Cardinals 2 New York Yanks, Dallas Texans, Baltimore Colts...3 Denver Broncos 4 Buffalo Bills, Los Angeles Rams, San Diego Cha...
Smushing the Data Together
Now that the two initial datasets have been read into Pandas dataframes, it’s time to smush them together in a way that makes them useful for further analysis. The first step I take is adding a new variable to the Quarterback Stats Table (qbs) called ‘qboc’. I set all the values to 0 for right now.
qbs['qboc']=0
Once again check to make sure the variable was added to the dataframe as expected.
print(qbs.head())#OutputPlayer Total 20092010201120122013201420152016...\0 A.Dalton 2500411501...1 A.Luck 1700053411...2 A.Rodgers 4133352254...3 A.Smith 2311111641...4 B.Bortles 1200000121...2023 Games Per Game Attempts Per 100 Att Sacked Per Sack \001700.1555570.453610.06910940.1836200.471860.091202280.1878400.525420.076301490.1546480.493670.06340790.1527190.442010.060 Sack Per Att Third Down % qboc 00.06540.00010.05129.41020.06939.02030.07926.09040.07433.330[5 rows x 26 columns]
The ‘qboc’ column was added to the end of the dataframe. The next step I take is to make the qbs[‘Player’] and the qbs_oc[‘short_name’] columns the indexes of the dataframes. This will speed up the comparison process. Although it wouldn’t be noticeable with these datasets, if you have a dataset will millions of records, it will bog down the system… ask me how I know.
Now this is the really fun part. All I need to do now is compare the indexes of the two dataframes. If the indexes match, then I can assign a ‘1’ to the qbs[‘qboc’] variable to signify that that quarterback is indeed a quarterback of color.
qbs.loc[(qbs.index.isin(qbs_oc.index)),'qboc']=1
This one line of code is pretty cool, I think. I want to dig into what this line actually does. I know this isn’t a Python coding post, but explaining will only take a minute and it unpacks some interesting concepts.
qbs.index and qbs_oc.index specify that we are going to be doing something with the indexes of the two dataframes.
The .isin is a function that returns a Boolean mask. So what (qbs.index.isin(qbs_oc.index) does is takes the index values of the qbs_oc dataframe and look to see if those values are in the qbs dataframe index. If they are, then the Boolean value = True, if not, the value = False. You can also save that part of the code to a variable and use over and over in other parts of your project, but in this instance, we don’t need to.
The qbs.loc is locating all the the indexes in the qbs dataframe where the mask value = True.
‘qboc’ specifies the column we want to assign our value to. In this case a 1 to signify that the quarterback is a person of color.
The qbs.loc() designates the dataframe we are intending to modify; (qbs.index.isin(qbs_oc.index)) designates the row we want to work with; and ‘qboc’ designates the column.
print(qbs.head())#Output Total 200920102011201220132014201520162017...\Player ...A.Dalton 25004115011...A.Luck 17000534110...A.Rodgers 41333522540...A.Smith 23111116415...B.Bortles 12000001217...2023 Games Per Game Attempts Per 100 Att Sacked Per Sack \Player A.Dalton 01700.1555570.453610.069A.Luck 0940.1836200.471860.091A.Rodgers 02280.1878400.525420.076A.Smith 01490.1546480.493670.063B.Bortles 0790.1527190.442010.060 Sack Per Att Third Down % qboc Player A.Dalton 0.06540.000A.Luck 0.05129.410A.Rodgers 0.06939.020A.Smith 0.07926.091B.Bortles 0.07433.330
As you can see, A.Smith now has a 1 in the qboc column. However, the A.Smith in the qbs data set is actually Alex Smith not Akili Smith who is the actual quarterback referenced in the qbs_oc dataset. This illustrates the importance of going through your data to ensure accuracy. Luckily these datasets are small enough to go through to spot any errors.
double_check = qbs.loc[(qbs['qboc']==1)]print(double_check.index)#OutputIndex(['A.Smith','C.Kaepernick','C.Newton','D.Prescott','D.Watson','G.Smith','J.Brissett','J.Campbell','J.Freeman','J.Hurts','J.Winston','K.Murray','L.Jackson','M.Vick','P.Mahomes','R.Griffin III','R.Wilson','T.Bridgewater','T.Taylor'],dtype='object',name='Player')qbs['qboc']['A.Smith']=0print(qbs)#Output Total 200920102011201220132014201520162017...\Player ...A.Smith 23111116415...2023 Games Per Game Attempts Per 100 Att Sacked Per Sack \Player A.Smith 01490.1546480.493670.063 Sack Per Att Third Down % qboc Player A.Smith 0.07926.090[1 rows x 25 columns]
Next Steps
Get ready for some quarterback madness in the upcoming post! We’ll be diving into our fancy new quarterbacks table and unleashing some wild analysis on the gridiron.
Once upon a time, in the realm of weather-related nerdiness, I embarked on a quest to decipher the secrets of changing weather patterns. Armed with my mighty keyboard and a burning hatred for sweltering summers, I planned to uncover the truth about my local area’s climate evolution. You see, summer and I have never been the best of friends. The scorching heat and suffocating humidity make me cringe harder than a cat stuck in a cucumber maze. So, I figured, why not dive into the delightful world of data and investigate if there’s any hope for an early arrival of autumn? I dubbed it my “Project Meteorological Marvel.”
My cunning plan involved sifting through decades of weather records, gathering juicy tidbits on how temperatures have tortured us poor mortals over the years. I wanted to spot trends, make dazzling graphs, and perhaps even predict when autumn would grace us with its blessed presence. Oh, how I yearned for a reliable sign that summer’s reign of terror would soon be over! Of course, this was no ordinary undertaking. I needed a trustworthy data source, and what better place to turn to than the National Oceanic and Atmospheric Administration (NOAA)? If you can’t trust the NOAA to provide accurate historical weather data, well, I guess we’re all doomed!
Now, I must confess, I had no intention of becoming a weather forecaster during this escapade. That’s a whole different level of sorcery reserved for the truly brave and slightly crazy souls. No, my friends, my mission was solely to unravel the mysteries of the past, not predict the future. So, off I went, armed with my web-scraping skills and a fervent desire to put an end to endless summers. And thus, my epic journey into the realm of weather data began… but did it?
Well, it seems that once people discover your supreme data-crunching powers, they start throwing project ideas at you like confetti at a parade. Take my poor, football-obsessed husband for example. He came up with the brilliant notion of analyzing if there’s any connection between a quarterback’s race and the number of times they get a sweet, sweet roughing the passer call in their favor. And as if that wasn’t enough, I thought, why not spice it up even more and explore if the defender’s race also plays a role in how many roughing the passer flags rain down upon them? Heck, let’s even toss in the officials’ race for good measure. Who knew the football field could have so many hidden layers of sociology and statistics? But hey, I’ll play along and start with quarterbacks for now. Let the mind-boggling journey begin! Just don’t blame me if we end up in a statistical black hole of absurdity.
At first, I was going to look at NCAA football statistics given that the sample size would be much larger than for the NFL. However, I didn’t really find a good source for the data to either download or extract. It just doesn’t seem like the NCAA collects that data down to the player level. As luck would have it I was able to find a source for NFL penalty data. the aptly named NFL Penalties is a sited dedicated to capturing penalty data so that users can basically settle disputes “over a player and their frequent ability to get away with murder, or not.” The site’s author does a pretty good job at articulating problems with the data and any mitigation actions taken. Ultimately the data on the site is provided by nflfastR. 1
Now that I’ve talked about the general concept and the search for a data source, here my next steps.:
Collect Roughing the Passer (RTP) data for the quarterback from NFL Penalties.
Collect the relevant biographical data on each of the quarterbacks.
Use Python and relevant libraries such as Pandas2 and matplotlib3 to perform data cleaning, exploration, univariate and bivariate analysis, and visualizations.
Publish the findings along with the documented methodology.
I’m not sure how long this will take me, could be a day, could be weeks. Either way, check back often for updates on the project’s progress.
Carl S, Baldwin B (2023). nflfastR: Functions to Efficiently Access NFL Play by Play Data. https://www.nflfastr.com/, https://github.com/nflverse/nflfastR. ↩︎
The pandas development team. (2023). pandas-dev/pandas: Pandas (v2.1.0). Zenodo. https://doi.org/10.5281/zenodo.8301632 ↩︎