<jupyter_start><jupyter_text>Import Data and Packages  Packages<jupyter_code>!pip install cpi
import pandas as pd
import plotly.graph_objects as go
import plotly.graph_objects as go
import cpi
cpi.update()<jupyter_output><empty_output><jupyter_text>Data  Revenues<jupyter_code>rev = pd.read_csv('../Assets/Revenues - Sheet1.csv')

# Remove newline char from columns
rev.columns = [col.replace("\n", "") for col in rev.columns]

# Set index to years
rev = rev.set_index('Year')

rev.head()<jupyter_output><empty_output><jupyter_text>Make Adjustments  Adjust for Inflation<jupyter_code>rev = rev.T
for i in range(1962, 2019):
    rev[i] = rev[i].apply(lambda x: cpi.inflate(x, i))
rev = rev.T
rev.head()
data_cols = rev.drop(columns = ['Total']).columns.to_list()

years = rev.index.to_list()

fig = go.Figure(data = [go.Bar(name = col, x = years, y = rev[col]) for col in data_cols])

# Change the bar mode
fig.update_layout(barmode='stack')
fig.show()<jupyter_output><empty_output><jupyter_text>Adjust for Population<jupyter_code>pop = pd.read_csv('../Assets/US Population - Sheet1.csv')
pop = pop.set_index('Year')
pop.tail()
rev = rev.T
for i in range(1962, 2020):
    rev[i] = rev[i].apply(lambda x: x / (pop.loc[i, 'Population'] / 1000000000))
rev = rev.T
rev.tail()
data_cols = rev.drop(columns = ['Total']).columns.to_list()

years = rev.index.to_list()

fig = go.Figure(data = [go.Bar(name = col, x = years, y = rev[col]) for col in data_cols])

# Change the bar mode
fig.update_layout(barmode='stack')
fig.show()<jupyter_output><empty_output><jupyter_text>Normalize<jupyter_code>import plotly.graph_objects as go

years = rev.index.to_list()

fig = go.Figure()

fig.add_trace(go.Scatter(
    x = years, y = rev['Individual Income Taxes'],
    mode='lines',
    #line=dict(width=0.5, color='rgb(184, 247, 212)'),
    stackgroup='one',
    groupnorm='percent', # sets the normalization for the sum of the stackgroup
    name = 'Individual Income Taxes'
))

for col in rev.columns.to_list()[1:]
    fig.add_trace(go.Scatter(
        x = years, y = rev[col],
        mode='lines',
        stackgroup='one',
        name = col
    ))  

fig.update_layout(
    showlegend=True,
    xaxis_type='category',
    yaxis=dict(
        type='linear',
        range=[1, 100],
        ticksuffix='%'))

fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1545376712328767, 'fraction_numerical': 0.018835616438356163, 'mean_word_length': 4.422273781902552, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '593422', 'license': 'MIT', 'n_tokens_mistral': 920, 'n_tokens_neox': 863, 'n_words': 188, 'path': 'Notebooks/Revenue.ipynb', 'repo_name': 'mkirby1995/federal-spending', 'size': '2336'}