+++ title = "Credit Card Spending Dashboards" date = "2020-06-16" +++ gspread_test
In [18]:
import pandas as pd
import gspread
import matplotlib.pyplot as plt
In [2]:
gc = gspread.service_account()

sh = gc.open_by_key("1_tbwz6Z9uVZMJQZTysSQJYbSg-LCRdk6u49UngChM-Y")
worksheet = sh.worksheet("Responses Raw")

dataframe = pd.DataFrame(worksheet.get_all_records())
In [3]:
dataframe["Incurring Month"] = pd.to_datetime(dataframe["Incurring Date"]).dt.strftime(
    "%Y%m"
)
df_filtered = dataframe[~dataframe["Category"].isin(["Fake", "Travel"])]

Monthly Details

In [28]:
df_by_monthly = pd.pivot_table(
    df_filtered,
    index="Incurring Month",
    columns="Category",
    values="Amount of Money",
    aggfunc=sum,
)
df_by_monthly.fillna(0)
Out[28]:
Category Activities Bills Deposit Dining Dispute Entertainment Gas Groceries Lifetime activities Shopping
Incurring Month
201904 0.0 222.68 0.00 0.00 0.00 113.50 0.00 0.00 0.0 0.00
201905 234.0 338.58 0.00 307.66 0.00 178.84 161.62 281.92 0.0 132.23
201906 0.0 143.24 0.00 345.08 0.00 134.17 150.79 343.41 0.0 680.92
201907 0.0 923.23 0.00 282.23 0.00 161.12 201.25 508.38 0.0 346.32
201908 312.0 416.79 0.00 267.68 0.00 54.55 121.98 364.14 0.0 239.29
201909 0.0 410.51 0.00 281.12 0.00 221.05 129.97 425.75 0.0 170.33
201910 0.0 550.25 0.00 458.67 0.00 259.90 122.33 259.79 0.0 0.00
201911 0.0 410.73 0.00 413.83 0.00 38.78 166.49 331.74 0.0 779.81
201912 0.0 393.31 0.00 318.41 0.00 54.75 88.22 238.69 0.0 901.00
202001 0.0 375.33 0.00 577.32 0.00 37.00 87.90 266.09 0.0 898.55
202002 0.0 380.71 0.00 314.66 0.00 0.00 81.64 415.99 0.0 375.22
202003 0.0 421.82 0.00 398.82 0.00 29.99 28.87 833.66 0.0 53.34
202004 0.0 438.68 0.00 293.78 0.00 143.89 0.00 828.30 0.0 55.04
202005 0.0 325.94 550.94 352.48 52.47 0.00 68.74 466.27 0.0 117.67
202006 0.0 179.00 0.00 110.92 0.00 0.00 0.00 146.48 9.0 124.88
In [26]:
df_by_monthly_plot = df_by_monthly.plot.bar(stacked=True, figsize=(16, 9))
df_by_monthly_plot.set_ylabel("Total Amount ($)")
plt.xticks(rotation=45);

Travel Details

In [30]:
df_travel = dataframe[
    (dataframe["Category"] == "Travel") & (dataframe["Travel Tag"] != "")
]
In [31]:
df_travel_by_tag = pd.pivot_table(
    df_travel,
    index="Travel Tag",
    columns="Travel Details",
    values="Amount of Money",
    aggfunc=sum,
    margins=True,
)
df_travel_by_tag = (
    df_travel_by_tag.sort_values(["All"], ascending=False)
    .drop("All", axis=1)
    .drop("All")
)
df_travel_by_tag.fillna(0)
Out[31]:
Travel Details Accomendation Airline Dining Gas Grocery Misc Public Transportation Rental Car Shopping Tour Ticket
Travel Tag
Hawaii Trip 2192.48 1941.98 585.90 81.81 164.95 26.0 108.49 324.45 235.51 536.54
Yellow Stone NP Trip 1678.58 664.00 370.11 51.81 80.11 0.0 114.30 366.52 263.64 167.88
Golden Pines RV Resort 135.36 0.00 0.00 185.83 139.60 6.0 0.00 302.80 8.04 10.00
Redwood State Park RV Camping 77.99 0.00 0.00 131.94 141.21 0.0 0.00 230.75 17.61 0.00
Pinnacles NP Trip 60.00 0.00 0.00 0.00 0.00 0.0 0.00 0.00 10.75 0.00
In [32]:
df_travel_by_tag_plot = df_travel_by_tag.plot.bar(stacked=True, figsize=(12, 8))
df_travel_by_tag_plot.set_ylabel("Total Amount ($)")
plt.xticks(rotation=45);
In [ ]: