-
Notifications
You must be signed in to change notification settings - Fork 45
2014 Minnesota Budget
Rodrigo Palacios edited this page Apr 17, 2015
·
3 revisions
%matplotlib inline
import re
import pandas as pd
from requests import get
from libextract import extract
from libextract.strategies import TABULAR
# fuzzy-table-formatter branch
# https://github.com/datalib/libextract/tree/fuzzy-table-formatter
from libextract import prototypes
url = "https://www.revisor.mn.gov/laws/?year=2014&type=0&doctype=Chapter&id=294"
minn2014 = get(url)
strat = TABULAR + (prototypes.convert_table,)
tabs = list(extract(minn2014.content, strategy=strat))
table = tabs[1]
df = pd.DataFrame.from_dict(table)
#convert
def convert_num(n):
return float(n.replace(',','').replace('(','').replace(')',''))
df['2'] = df['2'].apply(convert_num)
final_df = df[['0','2']]
final_df.columns = ['Expense Name', 'Amount']
expense_df = final_df.sort(columns='Amount')
expense_df = expense_df.set_index('Expense Name')
exclude_index = ["TOTAL", "Bond Proceeds Fund (General Fund Debt Service)"]
small_expense = expense_df[(expense_df.index != exclude_index[0]) &
(expense_df.index != exclude_index[1])]
pd.options.display.mpl_style = 'default'
small_expense.plot(kind='barh', figsize=[6, 10],
title="2014 MN Capital Budget Spending")