40 Getting CSVs from Sports Reference
Every table of data on Sports Reference can be turned into a csv using the magic of copy and paste. There’s some tricks to it.
Step 1: In R Studio, open a plain text file.
Step 2: On the table you want in Sports Reference, find the Share & Export tab and go to Get table as CSV (For Excel). NOTE: THIS TABLE HAS TWO HEADER ROWS. You will need to fix that later.
Step 3: Highlight and copy the data from Sports Reference.
Step 4: Paste it into your plain text file in R Studio and fix your headers. Remember that data in R – and pretty much every other data analysis platform – must have one row for headers. What you need to do now, in the text file, is check and see if you have any headers in that second row that repeat. If you have multiple G for goals – one is total goals, one is goals per something – you need to fix that manually. In my example, the first row is header names and none of them repeat. I’m good to move forward.
Step 6: Save your text file as whatever you want to name it DOT csv and put it where you’ve got your project data.
Step 7: Import your data like you would in any other assignment. You just created a CSV file.