I'm trying to fetch SQL Query to Pandas Data Frame using Jupyter Notebook.
I followed these instruction from beardc:
import pandas as pd
df = pd.read_sql(sql, cnxn)
cnxn = pyodbc.connect(connection_info)
cursor = cnxn.cursor()
sql = """SELECT * FROM AdventureWorks2012.Person.Address
WHERE City = 'Bothell'
ORDER BY AddressID ASC"""
df = psql.frame_query(sql, cnxn)
cnxn.close()
However, whenever I run the code it shows:
NameError
Traceback (most recent call last)
<ipython-input-5-4ea4efb152fe> in <module>()
1 import pandas as pd
2
3 df = pd.read_sql(sql, cnxn)
4
5 cnxn = pyodbc.connect(connection_info)
NameError: name 'sql' is not defined
I'm using a monitored-network (company network if anyone asks).
There are some questions I want to ask:
- Do I have to change the
connection_info
into the info in my database? - Is it important that I'm connected to a network that might have restriction on port connection? as the company sets up some of those.
I'm using the latest Anaconda Distribution.