How To Run Queries Against SQL Server (Or Any Database) Using Pandas

preview_player
Показать описание
In this video, I am going to show you how to run query against Microsoft SQL Server (or any database system) using Pandas in Python.

► Buy Me a Coffee? Your support is much appreciated!
-------------------------------------------------------------------------------------------
☕ Venmo: @Jie-Jenn

► Support my channel so I can continue making free contents
---------------------------------------------------------------------------------------------------------------

#pandas #pandastip #pandastutorial
Рекомендации по теме
Комментарии
Автор

Thank you very much, thanks to your help I was able to make the connection using SQLAlchemy

ronildosantos
Автор

Love your stuff Jie - unfortunately this didn’t work for me so I had to look for other methods. My solution that ended up working is below:

from sqlalchemy import create_engine
from sqlalchemy.engine import URL
import pyodbc
import pandas as pd

connection_string =
connection_url = URL.create(“mssql+pyodbc”, query={“odbc_connect”: connection_string})
engine = create_engine(connection_url)

query = “select top 10 * from yourtable;”

df = pd.read_sql(query, engine)
df

bf
Автор

Thank you, exactly what I was looking for

evedickson
Автор

I HAVE BEEN LOOKING FOR THIS SOLUTION FOR MONTHS NOW! Thank you!

Is there a way to point to sql queries saved in a folder instead of having to paste a sql query? Like say sql_statement = SQLqueryFileName ?

rykemoore
Автор

Hey Jie, thank you for sharing this content. I couldn't load table from ms sql server. This is the error message I got: 'OptionEngine' object has no attribute 'execute'

kayodeoyeniran
Автор

How do you create the class URL create?

maria-utxm
Автор

Would you know why in this passage:



connection_url = URL.create(mssql+pyodbc, query={"odbc_connect": connection_string})

engine = create_engine(connection_url, module= odbc)

I get the following error:

AttributeError Traceback (most recent call last)

in <module>

----> 1 connection_url = URL.create(mssql+pyodbc, query={"odbc_connect": connection_string})

2 engine = create_engine(connection_url, module= odbc)



AttributeError: type object 'URL' has no attribute 'create'

maria-utxm
Автор

how to run the selected code in Windows?

rajkumarrajan
Автор

Hi thanks for sharing.. I tried the script and there is an error —> NameError: name ‘URL’ is not defined.. I have already installed sqlalchemy.. any idea why the error appeared?

raihanahrazak
Автор

I get AttributeError: module "sqlalchemy.engine.url' has no attribute 'create', would you know how to fix it?

maria-utxm