Introduction to the Pandasql Library

Using the Pandasql Library

As it is the case for any new library you want to use in Python, the first step is to make sure to download the library. One of the easiest ways is to use the pip installer.

pip install pandasql
from pandasql import sqldf
sql = lambda q: sqldf(q, globals())

Writing Queries

Writing queries using the function from the pandasql library is as easy as writing a query in a SQL database. The library specifically uses the syntax from the sqlite version of SQL. This means that the majority of SQL statements and functions are available to you.

q = """
SELECT *
FROM clients
WHERE state = "Virginia";
"""
results = sql(q)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store