Skip to content

Instantly share code, notes, and snippets.

View jhconning's full-sized avatar

Jonathan Conning jhconning

View GitHub Profile
@jhconning
jhconning / Interactive Ricardo Viner3.ipynb
Last active October 8, 2015 03:02
Interactive Ricardo Viner with Bokeh
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhconning
jhconning / BokehSliderLines.ipynb
Last active October 8, 2015 02:50
Very simple example of an ipywidgets slider working with a Bokeh plot
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhconning
jhconning / 0_reuse_code.js
Created December 16, 2015 13:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#df is the original dataframe with a list of names you want to prevail
#dfF is the dataframe with Names that can be matched only fuzzily
#For each Name in df the code finds the most likely match from the dfF and saves that name
#We then merge on that new key 'Name_r'
#some code is to cover the event of no match (perhaps b/c df has names not in dfF)
# From http://stackoverflow.com/questions/13636848/is-it-possible-to-do-fuzzy-match-merge-with-python-pandas
# http://stackoverflow.com/questions/36557722/python-pandas-difflib-throws-list-index-out-of-range-error
@jhconning
jhconning / Folium_markers
Created March 7, 2017 18:52
Folium map markers and zipfile
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mapping largest cities\n",
"## Experiments with folium, zipfile and pandas"
]
},
@jhconning
jhconning / gist:6e6fafa15af5c1f87237e7c50a20f4c3
Created May 2, 2017 02:01
pandas: list comprehension to drop columns that match condition
def drop_cols(df):
'''drop columns that don't vary'''
df.drop([ col for col in df.columns if (len(df[col].unique()) == 1)],
axis=1, inplace=True)
@jhconning
jhconning / aganalytics_python.api.ipynb
Created May 5, 2017 19:33
sample python code for ag-analytics.org API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhconning
jhconning / gist:22faf25a9203c3c592caf7eb07f866fc
Created May 6, 2017 03:00
pandas multiindex and groupby
# to create a multinindex
df.sort_values(by = ['Year', 'UnitDesc','bin'], inplace = True)
df = df.set_index(['Year', 'UnitDesc','bin'],drop = False)
# To turn one level of the index into a column
df = df.unstack('UnitDesc')['Value']
df.head()
# to pull out all data in level='Year'
@jhconning
jhconning / gist:5d1b1310d4cfb61639aec78618dda7d5
Created May 26, 2017 06:12
Sympy latex printing in jupyter
from sympy import init_printing; init_printing(use_latex='mathjax')
@jhconning
jhconning / gist:9e0b6cf4900a46e4400d3ee6c3b517b9
Created July 4, 2017 01:29
read SQL into pandas with pymysql
import pandas as pd
import pymysql
mysql_connection = pymysql.connect(host='localhost',
user='root',
password='',
db='tutorfall2016',
charset='utf8',
cursorclass=pymysql.cursors.DictCursor)