Answers for "read sql to a pandas df"

2

SQL to DataFrame

import pandas as pd
import pyodbc 
conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=RONSQLEXPRESS;'
                      'Database=TestDB;'
                      'Trusted_Connection=yes;')

cursor = conn.cursor()

sql_query = pd.read_sql_query('SELECT * FROM TestDB.dbo.Person',conn)
print(sql_query)
print(type(sql_query))
Posted by: Guest on May-16-2021
0

run sql query on pandas dataframe

from pandasql import sqldf

output = sqldf("select * from df")
Posted by: Guest on May-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language