Skip to content

Instantly share code, notes, and snippets.

@dword4
Created January 3, 2018 21:00
Show Gist options
  • Save dword4/11842fa4c588451e0da3977c9d5aad76 to your computer and use it in GitHub Desktop.
Save dword4/11842fa4c588451e0da3977c9d5aad76 to your computer and use it in GitHub Desktop.
quick bit of python to figure out how much has been spent on any given thing
#!/usr/bin/python3
import pandas as pd
import numpy as np
import sys
target = sys.argv[1]
def getTargetTotal(target):
df = pd.read_csv('data.csv', header=None,names=['date','description','ammount','balance'])
df.replace('(^\-\$)', '', regex=True, inplace=True)
Total = df.loc[df['description'].str.contains(target),'ammount'].sum()
df2 = pd.to_numeric(df.loc[df['description'].str.contains(target),'ammount'])
return df2.sum()
def getTargetCount(target):
df = pd.read_csv('data.csv', header=None,names=['date','description','ammount','balance'])
df.replace('(^\-\$)', '', regex=True, inplace=True)
Total = df.loc[df['description'].str.contains(target),'ammount'].sum()
df2 = pd.to_numeric(df.loc[df['description'].str.contains(target),'ammount'])
return df2.count()
print("Total:",getTargetTotal(target),"$")
print("Transactions:",getTargetCount(target))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment