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)
Date | Sales | |
0 | 9/21/2021 | 7157678 |
---|---|---|
1 | 9/22/2021 | 8188758 |
2 | 9/23/2021 | 7465293 |
3 | 9/24/2021 | 562583 |
4 | 9/25/2021 | 9054512 |