Baseball Savant Data Scraping Example

Example Database Creation

This example creates a small sample of the full database saved to "baseball_savant.db", a portable SQLite database.


In [ ]:
import sqlite3
import pandas as pd
import savantscraper

# Example for two years and two teams
savantscraper.database_import('baseball_savant',
                              (2017, 2018),
                              teams=['STL', 'COL'])

Example Query

This example connects to the database and creates a pandas dataframe from a simple query.


In [ ]:
# Connect to the database
conn = sqlite3.connect('baseball_savant.db')

# Query the database and load into a pandas dataframe
df = pd.read_sql_query("select player_name, vx0 from statcast limit 5;", conn)

# Close connection when finished
conn.close()

df

In [ ]: