Skip to content

Instantly share code, notes, and snippets.

from IPython import display
import matplotlib.pyplot as plt
from revoscalepy import RxInSqlServer, rx_exec
# create a remote compute context with connection to SQL Server
sql_compute_context = RxInSqlServer(connection_string = connection_string.format(new_db_name))
# use rx_exec to send the function execution to SQL Server
image = rx_exec(send_this_func_to_sql, compute_context = sql_compute_context)[0]
# only an image was returned to my jupyter client. All data remained secure and was manipulated in my db.
display.Image(data=image)
def send_this_func_to_sql():
from revoscalepy import RxSqlServerData, rx_import
from pandas.tools.plotting import scatter_matrix
import matplotlib.pyplot as plt
import io
# remember the scope of the variables in this func are within our SQL Server Python Runtime
connection_string = "Driver=SQL Server;Server=localhost\MSSQLSERVER2017;Database=MLRemoteExec;Trusted_Connection=Yes;"
# specify a query and load into pandas dataframe df
from revoscalepy import RxSqlServerData, rx_data_step
# Example of using RX APIs to load data into SQL table. You can also do this with pyodbc
table_ref = RxSqlServerData(connection_string=connection_string.format(new_db_name), table="Iris")
rx_data_step(input_data = df, output_file = table_ref, overwrite = True)
print("New Table Created: Iris")
print("Sklearn Iris sample loaded into Iris table")
from sklearn import datasets
import pandas as pd
# SkLearn has the Iris sample dataset built in to the package
iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
import pyodbc
# creating a new db to load Iris sample in
new_db_name = "MLRemoteExec"
connection_string = "Driver=SQL Server;Server=localhost\MSSQLSERVER2017;Database={0};Trusted_Connection=Yes;"
# you can also swap Trusted_Connection for UID={your username};PWD={your password}
cnxn = pyodbc.connect(connection_string.format("master"), autocommit=True)
cnxn.cursor().execute("IF EXISTS(SELECT * FROM sys.databases WHERE [name] = '{0}') DROP DATABASE {0}".format(new_db_name))
cnxn.cursor().execute("CREATE DATABASE " + new_db_name)
cnxn.close()
@kywe665
kywe665 / install-syntastic.sh
Created May 7, 2012 17:41 — forked from coolaj86/install-syntastic.sh
vim? JavaScript? syntastic!
# This is how you install syntax checking for JavaScript in vim
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
npm install -g jshint
cd ~/.vim/bundle
git clone https://github.com/scrooloose/syntastic.git
@kywe665
kywe665 / install-syntastic.sh
Created May 7, 2012 17:41 — forked from coolaj86/install-syntastic.sh
vim? JavaScript? syntastic!
# This is how you install syntax checking for JavaScript in vim
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
npm install -g jshint
cd ~/.vim/bundle
git clone https://github.com/scrooloose/syntastic.git
@kywe665
kywe665 / install-syntastic.sh
Created May 7, 2012 17:40 — forked from coolaj86/install-syntastic.sh
vim? JavaScript? syntastic!
# This is how you install syntax checking for JavaScript in vim
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
npm install -g jshint
cd ~/.vim/bundle
git clone https://github.com/scrooloose/syntastic.git
@kywe665
kywe665 / install-syntastic.sh
Created May 7, 2012 17:40 — forked from coolaj86/install-syntastic.sh
vim? JavaScript? syntastic!
# This is how you install syntax checking for JavaScript in vim
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
npm install -g jshint
cd ~/.vim/bundle
git clone https://github.com/scrooloose/syntastic.git