You may have a set or tables (or better yet a view of cleaned data in MS SQL Server) and want to bring it in as a DataFrame. This simple .ipynb should be enough to get your started using the pymssql library.
db_reader
and the password is passme123
. Create an account such as this to access the desired database on your server.# uncomment and run this if not loaded...
# !pip install pymssql
import pandas as pd
import pymssql
conn = pymssql.connect('localhost', 'db_reader', 'passme123', 'Titanic')
cursor = conn.cursor(as_dict=True)
lst = []
cursor.execute('SELECT p.* FROM dev.passengers p;')
for row in cursor:
lst.append(row)
df = pd.DataFrame(lst)
# close your cursor, followed by your connection
cursor.close()
conn.close()
# access your df (sql results like any other df)
df
ID | Gender | Boarded | Class | Yrs | Survived | |
---|---|---|---|---|---|---|
0 | 1 | 0 | 2 | 3 | 26.0 | 1 |
1 | 2 | 0 | 1 | 3 | 42.0 | 0 |
2 | 3 | 1 | 1 | 3 | 39.0 | 1 |
3 | 4 | 0 | 1 | 3 | 16.0 | 0 |
4 | 5 | 0 | 1 | 3 | 14.0 | 0 |
... | ... | ... | ... | ... | ... | ... |
1312 | 1313 | 1 | 1 | 2 | 24.0 | 0 |
1313 | 1314 | 0 | 2 | 3 | 27.0 | 0 |
1314 | 1315 | 0 | 2 | 3 | 22.0 | 0 |
1315 | 1316 | 0 | 2 | 3 | 22.0 | 1 |
1316 | 1317 | 0 | 1 | 3 | 29.0 | 0 |
1317 rows × 6 columns