Loading data into PostgreSQL tables
To complete the data pipeline, you need to load the transformed data into the final output locations – the PostgreSQL data tables – so that your client can easily access and use them. In this section, you will load the cleaned data into the PostgreSQL chicago_dmv
schema using the psycopg2
Python module. As you may recall from the previous chapter, psycopg2
is a Python package that enables you to connect your Python (or Jupyter Notebook) script to PostgreSQL. Use the following code to establish a connection to the database from your Jupyter Notebook:
import psycopg2# Establish connection to the Postgresql database conn = psycopg2.connect(database="your_database_name", Â Â Â Â user="your_username", password="your_password", Â Â Â Â host="your_host", port="your_port") # Create a cursor object cur = conn.cursor()
Using SQL statements in Python, denoted...