<jupyter_start><jupyter_text><jupyter_code>%%time
!git clone https://github.com/sbooeshaghi/SBA-PPP-Loan-Data.git
!unzip /content/SBA-PPP-Loan-Data/over_150k/foia_150k_plus.csv.zip
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from google.colab import data_table
data_table.enable_dataframe_formatter()

def nd(arr):
  return np.asarray(arr).reshape(-1)

def yex(ax):
    lims = [
        np.min([ax.get_xlim(), ax.get_ylim()]),  # min of both axes
        np.max([ax.get_xlim(), ax.get_ylim()]),  # max of both axes
    ]
    
    # now plot both limits against eachother
    ax.plot(lims, lims, 'k-', alpha=0.75, zorder=0)
    ax.set_aspect('equal')
    ax.set_xlim(lims)
    ax.set_ylim(lims)
    return ax

fsize=20

plt.rcParams.update({'font.size': fsize})
%config InlineBackend.figure_format = 'retina'<jupyter_output><empty_output><jupyter_text>Load data > $150k<jupyter_code>df = pd.read_csv("/content/foia_150k_plus.csv")
df.head()<jupyter_output><empty_output><jupyter_text>Make `df` more usable<jupyter_code>df.LoanRange.unique()
loan = {
    "a $5-10 million": {"lower": 5000000, "upper": 10000000},
    "b $2-5 million": {"lower": 2000000, "upper": 4999999},
    "c $1-2 million": {"lower": 1000000, "upper":1999999},
    "d $350,000-1 million": {"lower": 350000, "upper":999999},
    "e $150,000-350,000" : {"lower": 150000, "upper":349999}
}
df['loan_lower'] = df.LoanRange.apply(lambda x: loan[x]["lower"])
df['loan_upper'] = df.LoanRange.apply(lambda x: loan[x]["upper"])
df["date_approved_dt"] = pd.to_datetime(df["DateApproved"]).values<jupyter_output><empty_output><jupyter_text>Amount of loans over time<jupyter_code>fig, ax = plt.subplots(figsize=(21, 7))

x = df.groupby("date_approved_dt")["loan_lower"].sum().index.values
y = df.groupby("date_approved_dt")["loan_lower"].sum().values

yy = pd.DataFrame({"date":x, "csum": y}).set_index("date").cumsum().values
ax.scatter(x, y, color="k")

kwd = {
    "xlabel": "Date",
    "ylabel": "Lower loan amount"
}
ax.set(**kwd)
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('${x:,.0f}'))

plt.show()
fig, ax = plt.subplots(figsize=(21, 7))

x = df.groupby("date_approved_dt")["loan_lower"].sum().index.values
y = df.groupby("date_approved_dt")["loan_lower"].sum().values

yy = pd.DataFrame({"date":x, "csum": y}).set_index("date").cumsum().values

ax.plot(x, yy, linewidth=4, color="k")

kwd = {
    "xlabel": "Date",
    "ylabel": "Sum of loans given out"
}
ax.set(**kwd)
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('${x:,.0f}'))

plt.show()<jupyter_output><empty_output><jupyter_text>Number of loans per state<jupyter_code>pd.DataFrame(df[df.BusinessType.notna()]["BusinessType"].value_counts())
pd.DataFrame(df[df.State.notna()]["State"].value_counts())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19286471211586012, 'fraction_numerical': 0.04274108089014483, 'mean_word_length': 5.742857142857143, 'pattern_counts': {'":': 22, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 1, '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': '77309', 'license': 'MIT', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1137, 'n_words': 178, 'path': 'notebooks/data_summary.ipynb', 'repo_name': 'sbooeshaghi/SBA-Paycheck-Protection-Program-Loan-Level-Data', 'size': '2831'}