Skip to content

Instantly share code, notes, and snippets.

View rockinhumingbird's full-sized avatar
🎯
Focusing

rockinhumingbird

🎯
Focusing
View GitHub Profile
# Terminal Cheat Sheet
pwd # print working directory
ls # list files in directory
cd # change directory
~ # home directory
.. # up one directory
- # previous working directory
help # get help
-h # get help
from IPython.display import HTML
fig, ax = plt.subplots(figsize=(15, 8))
animator = animation.FuncAnimation(fig, draw_barchart,frames=(1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012))
HTML(animator.to_jshtml())
# .save as gif or mp4 fps is the speed and dpi is the resolution
animator.save('moneyraise.gif', fps=.5, dpi=200)
@rockinhumingbird
rockinhumingbird / m
Last active October 30, 2019 00:11
barchart
fig, ax = plt.subplots(figsize=(15, 8))
def draw_barchart(year):
dff = df[df['year'].eq(year)].sort_values(by='money_raised', ascending=True).tail(10)
ax.clear()
ax.barh(dff['candidate'], dff['money_raised'], color=[colors[groups[x]] for x in dff['candidate']])
dx = dff['money_raised'].max() / 200
# zip function use iterable objects to format the axes
for i, (value, name) in enumerate(zip(dff['money_raised'], dff['candidate'])):
ax.text(value-dx, i, name, size=14, weight=600, ha='right', va='bottom')
@rockinhumingbird
rockinhumingbird / m
Created October 29, 2019 19:13
Make color dictionary and group by party
# make colors dict so that later we can enumerate the elements
colors = dict(zip(['Republican', 'Democratic'],['#EE3B3B', '#00BFFF']))
groups = df.set_index('candidate')['party'].to_dict()
@rockinhumingbird
rockinhumingbird / rockinrobin
Created October 29, 2019 19:09
layout basics
latestyear = 2012
# Use eq() function to test for equality between a data frame object and a series object
lastestdf = (df[df['year'].eq(latestyear)].sort_values(by='money_raised',
ascending = True).head(10))
lastestdf
@rockinhumingbird
rockinhumingbird / rockin
Created October 29, 2019 19:05
import libraries
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.animation as animation
from IPython.display import HTML
import matplotlib.style as style
style.available
style.use('fivethirtyeight')