Skip to content

Instantly share code, notes, and snippets.

@JosephSalisbury
Created January 18, 2015 17:03
Show Gist options
  • Save JosephSalisbury/99d886948d72568c1d10 to your computer and use it in GitHub Desktop.
Save JosephSalisbury/99d886948d72568c1d10 to your computer and use it in GitHub Desktop.
Plot Natwest statements
#!/usr/bin/python
# -*- coding: utf-8 -*-
from dateutil import parser
from matplotlib import pyplot
from numpy import array
def convert_line_to_datetime(line):
""" Given a line, return the date of the line as a datetime object. """
tokens = line.split()
date_string = '%s %s %s' % (tokens[0], tokens[1], tokens[2])
date = parser.parse(date_string)
return date
def convert_line_to_amount(line):
""" Given a line, return the amount of the line as a float. """
tokens = line.split()
amount_string = tokens[-1].strip('-£')
amount_string = amount_string.replace(',', '')
amount = float(amount_string)
return amount
def plot_graph(datetimes, amounts):
""" Plot the datetimes against the amounts. """
pyplot.plot(datetimes, amounts)
pyplot.show()
def main():
with open('/home/joseph/Desktop/statement.txt') as f:
lines = f.readlines()
datetimes = map(convert_line_to_datetime, lines)
amounts = map(convert_line_to_amount, lines)
plot_graph(datetimes, amounts)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment