A simple example of connecting to SQL Server in Python, creating a table and returning a query into a Pandas dataframe.
- The example file shows how to connect to SQL Server from Python and then how to run queries and return query results as a Pandas data frame.
- Further analysis can be performed using Pandas.
- Install the packages - 'pandas' and 'pyodbc'
- Open the included .ipynb file
- Replace the details in the connection string with your SQL Server credentials
- Follow the steps in the file included in order to:
- Create a table
- Insert data
- Query the data
- Turn the data into a list of lists for each row
- Convert the list of lists into a pandas data frame
- If you are working with SQL Server Express or Developer edition and connect with Windows authentication, this line needs to be added to the connection string:
"Trusted_Connection=yes"
- This will ignore the UID and PWD and allow you to connect via Windows authentication.