def __init__(self, files): """ ==Parameters== |files| : entered in as a list """ self.self = self self.files = files cpi.update()
def __init__(self): self.self = self self.files = [ '/Users/jenniferpaige/code/DSI/getit/TTS_10-Dec-2019_p1.csv', '/Users/jenniferpaige/code/DSI/getit/TTS_10-Dec-2019_p2.csv' ] cpi.update()
def inflation_price_adjustment(price, base_year, target_year): if cpi.LATEST_YEAR < target_year: logger.info("Updating CPI data") cpi.update() if cpi.LATEST_YEAR < target_year: raise ValueError( f"CPI data are only available through {cpi.LATEST_YEAR}. Your target year is " f"{target_year}" ) price = price * cpi.inflate(1, base_year, to=target_year) return price
def _normalize_census_data(df: pd.DataFrame) -> pd.DataFrame: # Adjust for inflation cpi.update() df['home_value'] = df.apply( lambda x: cpi.inflate(x['home_value'], x['year']), axis=1) df['household_income'] = df.apply( lambda x: cpi.inflate(x['household_income'], x['year']), axis=1) # Normalize USD amounts grouped = df.groupby('geoid') for col in ('household_income', 'home_value'): df[f'relative_{col}'] = grouped[col].transform(lambda s: s / s.iloc[0]) # Normalize population composition population = df['population'] for col in df.columns: if col.startswith('pop_'): df[col] /= population return df
import pandas as pd import dash import dash_bootstrap_components as dbc import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output, State import plotly.graph_objects as go import cpi cpi.update() from app import app dis = pd.read_csv('Assets/Discretionary Outlays - Sheet1.csv') # Remove newline char from columns dis.columns = [col.replace("\n", "") for col in dis.columns] # Set index to years dis = dis.set_index('Year') mand = pd.read_csv('Assets/Mandatory Outlays - Sheet1.csv') # Remove newline char from columns mand.columns = [col.replace("\n", "") for col in mand.columns] # Set index to years mand = mand.set_index('Year') # Fill n.a. mand['Medicarea'] = mand['Medicarea'].replace('n.a.', 0) new_dis = dis.drop(columns=['Total']) new_mand = mand.drop( columns=['Total', 'Memorandum: Major Health Care Programs (Net)c']) spend = new_dis.join(new_mand, how='inner')