Managing data with Python
While psycopg2 is a powerful database client for accessing PostgreSQL from Python, it is just a connector. It does nothing more than pass the SQL and the resulting data between your program and the database server. If you only rely on psycopg2 for connection, you will very soon get lost in the swamp of SQL statements embedded in Python scripts. Fortunately, you can enhance the code by using a couple of other packages—namely, pandas and SQLAlchemy. While both packages are powerful, it is worth noting that they still use the psycopg2 package to connect to the database and execute queries. The big advantage that these packages provide is that they abstract some of the complexities of connecting to and working with the database, while dedicating the connectivity handling to the psycopg2 package. By abstracting these complexities, you can connect to the database without worrying that you might forget to close a connection or remove a Python object such...