Running SQL queries in Python using Pandasql library

Hello friends! today we’ll be learning how to run SQL queries in python using Pandasql library . I’ll quickly show 1 query for the beginning.

Importing library

import pandas as pd 
!pip install -U pandasql 
import pandasql as psql 

Loading Data

df1 = pd.read_csv("file1.csv")

Query

Q1 = """ SELECT * FROM df1""" 

Run query

psql.sqldf(Q1)
DateSales
09/21/20217157678
19/22/20218188758
29/23/20217465293
39/24/2021562583
49/25/20219054512

Leave a Reply

Your email address will not be published. Required fields are marked *