Skip to content

Instantly share code, notes, and snippets.

@pigidser
Forked from kolommik/connect_and_load.py
Last active April 25, 2022 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigidser/1c676812615cde5978318d62fee5fdd0 to your computer and use it in GitHub Desktop.
Save pigidser/1c676812615cde5978318d62fee5fdd0 to your computer and use it in GitHub Desktop.
Pandas and MSSQL
from bisect import bisect_right, bisect_left
def solution(A:list):
if len(A) == 0:
return 1
A.sort()
ind = bisect_left(A, 0)
if ind == len(A):
return A[ind-1] + 1 if A[ind-1] >= 0 else 1
A = A[ind:]
A.insert(0,0)
B = A.copy()
B.insert(0,B[0]-1)
B = B[:-1]
C = [element1 - element2 for (element1, element2) in zip(A, B)]
ind = bisect_left(C, 2)
return A[ind-1] + 1
import pymssql
import pandas as pd
## instance a python db connection object- same form as psycopg2/python-mysql drivers also
conn = pymssql.connect(server="172.0.0.1", user="howens",password="some_fake_password", port=63642) # You can lookup the port number inside SQL server.
## Hey Look, college data
stmt = "SELECT * FROM AlumniMirror..someTable"
# Excute Query here
df = pd.read_sql(stmt,conn)
df.head(5)
pymssql==2.1.0
pandas==0.14.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment