This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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') |
This file contains hidden or 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
| # 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() |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 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') |