#apply styles to notebook (rather than doing it locally # via the profile custom.css file) #from IPython.core.display import HTML #css_file = 'media/style.css' #HTML(open(css_file, "r").read()) import numpy as np import pandas as pd import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt %matplotlib inline #read in aggregated federal contract totals contracts = pd.read_csv('data/fed_contract_totals.txt') contracts = contracts[[ 'state_abbr', 'year', 'total_adj', 'dod_adj', 'non-dod_adj', 'total_per_capita_adj', 'dod_per_capita_adj', 'other_per_capita_adj', 'dod_percent_total', 'other_percent_total' ]] #take a peek at the data contracts.head() plottotal = contracts[['year', 'state_abbr', 'dod_adj', 'non-dod_adj']] #show total in millions of $ for readability plottotal['dod_adj'] = plottotal['dod_adj']/1000000 plottotal['non-dod_adj'] = plottotal['non-dod_adj']/1000000 plottotal = pd.melt(plottotal, id_vars=['year', 'state_abbr'], var_name = 'Contract Type', value_name = 'Amount') fg = sns.factorplot('year', 'Amount', 'Contract Type',data=plottotal[plottotal['state_abbr']=='VA'], kind='bar') fg.set_axis_labels('Fiscal Year', 'Amount (Millions of 2015 $)') plotpc = contracts[['year', 'state_abbr', 'dod_per_capita_adj', 'other_per_capita_adj']] plotpc = pd.melt(plotpc, id_vars=['year', 'state_abbr'], var_name = 'Contract Type', value_name = 'Amount') fg = sns.factorplot( 'year', 'Amount', 'Contract Type', plotpc[~plotpc['state_abbr'].isin(['DC', 'PR'])], col='state_abbr', col_wrap=4, kind='point' ) fg.set_axis_labels('Fiscal Year', 'Amount (2015 $)')