Last active
May 29, 2017 11:34
-
-
Save dkapitan/6faa41c621090fee080e62d6a70d666d to your computer and use it in GitHub Desktop.
Frequently used imports for jupyter notebooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import configparser | |
from sqlalchemy import create_engine | |
import pandas as pd | |
import numpy as np | |
import re | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# function to clean column names, | |
# based on https://stackoverflow.com/questions/3303312/how-do-i-convert-a-string-to-a-valid-variable-name-in-python | |
# since database only is case-insensitive, returns all lowercase | |
def clean_lower(s): | |
# replace spaces with underscores | |
s = s.replace(' ', '_') | |
# Remove invalid characters | |
s = re.sub('[^0-9a-zA-Z_]', '', s) | |
# Remove leading characters until we find a letter or underscore | |
s = re.sub('^[^a-zA-Z_]+', '', s) | |
return s.lower() | |
# define HOME path | |
HOME = os.path.expanduser('~') | |
# open database engine turing-prod:cbi | |
config = configparser.ConfigParser() | |
config.read(HOME + '/git/config.cfg') | |
cbi = create_engine(config['clinics_db_servers']['oz_epd'] + '/EPDyesterday') # use engine for pandas | |
%matplotlib inline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment