https://github.com/tomaztk/mssqlserver_pandas
Using Python Pandas dataframe to read and insert data to Microsoft SQL Server
https://github.com/tomaztk/mssqlserver_pandas
mssql mssqlserver pandas python python-pandas sql t-sql
Last synced: 6 days ago
JSON representation
Using Python Pandas dataframe to read and insert data to Microsoft SQL Server
- Host: GitHub
- URL: https://github.com/tomaztk/mssqlserver_pandas
- Owner: tomaztk
- Created: 2018-07-15T07:37:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T16:47:19.000Z (over 4 years ago)
- Last Synced: 2025-02-02T07:41:21.713Z (9 months ago)
- Topics: mssql, mssqlserver, pandas, python, python-pandas, sql, t-sql
- Language: Python
- Size: 23.4 KB
- Stars: 31
- Watchers: 5
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Using Microsoft SQL SQLSERVER with Python Pandas
Using **Python Pandas** dataframe to read and insert data to **Microsoft SQL Server**.

## Cloning the repository
You can follow the steps below to clone the repository.
```
git clone https://github.com/tomaztk/MSSQLSERVER_Pandas.git
```
## Quickstart from Microsoft SQL Server
1. Clone the repository
2. Get connection to your SQL Server 2017+
3. Start using MSSQL Server with Python Pandas
``` sql
-- sample table
SELECT TOP 10
name
,object_id
FROM sys.tables
EXECUTE sp_execute_external_script @language = N'Python'
,@script = N'
import pandas as pd
OutputDataSet = pd.DataFrame(InputDataSet);
'
, @input_data_1 = N'SELECT TOP 10 name,object_id FROM sys.tables'
WITH RESULT SETS((
[Name] VARCHAR(150) NOT NULL
,[object_ID] CHAR(20) NOT NULL
));
```
## Quickstart from Python IDE
1. Clone the repository
2. Open Python IDE
3. Enjoy
``` python
import pandas as pd
import pyodbc
sql_conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server}; \
SERVER=SQLSERVER2017;DATABASE=master;Trusted_Connection=yes')
query = "SELECT * FROM sys.tables"
df = pd.read_sql(query, sql_conn)
df.head(3)
```
## Collaboration and contributors
Contributions of any kind is highly appreciated! Fork the repository, add your code.
## Contact
Feel free to get in touch for questions regarding Python and MSSQL Server connectivity.