Member-only story
Pandas merge() and read_sql() — joining DataFrames.
I have written several articles recently, about pandas and PostgreSQL database interaction — specifically in loading CSV data. In this post, I’ll cover what I have recently learned using pandas merge()
and read_sql_query()
, retrieving query results using ‘s and similar queries.
OS, Database, and software used:
- Xubuntu Linux 18.04.2 LTS (Bionic Beaver)
- PostgreSQL 11.4
- Python 3.7.4
- pandas-0.25.0
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
Feel free to visit these similar posts about pandas and SQL…
- Pandas to SQL — importing CSV data files into PostgreSQL
- Basic CSV file import and exploration with Pandas — first steps.
- Pandas concat() then to_sql() — CSV upload to PostgreSQL
For starters, I import pandas, SQLAlchemy, and create a connection to the PostgreSQL database:
>>> import pandas as pd
>>> import sqlalchemy
>>> from sqlalchemy import create_engine
>>>…