{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pandas as pd\n", "from pandas import datetime\n", "import seaborn as sns\n", "from ipywidgets import interact\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import pyodbc\n", "import adodbapi\n", "%load_ext sql\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# MSSQL Management Studio Connection\n", "\n", "conn = pyodbc.connect('Driver={SQL server};'\n", " 'server=DESKTOP-DS7J579\\PYTHON_DA;'\n", " 'Database=AdventureWorks2012;'\n", " 'uid=PyXXXXXXXX;'\n", " 'pwd=PyXXXXXXXX;'\n", " 'trusted_connection=yes')\n", "cursor = conn.cursor()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Sample SQL Data pull\n", "\n", "df = pd.read_sql_query('select FirstName,'\n", " 'LastName,'\n", " 'City,'\n", " 'StateProvinceName '\n", " 'from Sales.vIndividualCustomer',conn)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FirstNameLastNameCityStateProvinceName
0AaronAdamsDowneyCalifornia
1AdamAdamsNewport BeachCalifornia
2AlexAdamsLake OswegoOregon
3AlexandraAdamsBurlingameCalifornia
4AllisonAdamsRoubaixNord
\n", "
" ], "text/plain": [ " FirstName LastName City StateProvinceName\n", "0 Aaron Adams Downey California\n", "1 Adam Adams Newport Beach California\n", "2 Alex Adams Lake Oswego Oregon\n", "3 Alexandra Adams Burlingame California\n", "4 Allison Adams Roubaix Nord" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display Query\n", "\n", "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }