Python Forum
Analyzing yearly expenses (CSV file) from debit card
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Analyzing yearly expenses (CSV file) from debit card
#1
Hello,

I am quite new with programming in Python and now I have started my (kind of) 'first' project in Python. I want to analyse my yearly expenses and I think pandas is the best way to give a clear overview with a chart.

The query:
  • I have a yearly overview of expenses in a CSV file (see attached). This is an example, not my 'real' expenses Tongue
  • The lay-out of the csv file ins't clear, so I want to change it. Preferred is have all the columns 'Alligned left' and the first row (headers) should be Bold.
  • The output of the chart should visualize my expenses monthly. In the end I want to have an overview in which month the expenses are high and in which months the expenses are relative low.
  • If the analysis is done and the chart is made. I want to save the file with _MODIFIED added to the original file.

I tried starting this project with open and edit a CSV file using the following code:
import csv
from pathlib import Path
from tkinter.filedialog import askopenfilename
import sys
 
 
def read_csv_file(filename):
    parts = list(filename.parts)
    parts[-1] = f"{filename.stem}Modified{filename.suffix}"
    parts[0] = ''
    outfilename = Path(f"{'/'.join(parts)}")
 
    print(f"new output file name: {outfilename}")
 
    with filename.open() as fp, outfilename.open('w') as fout:
        crdr = csv.reader(fp, delimiter=',')
        cwrtr = csv.writer(fout, delimiter=',')
        for row in crdr:
            print(row)
            # Modify row as desired here
            cwrtr.writerow(row)
 
def get_filename():
    badcount = 0
 
    while(True):
        try:
            if badcount > 2:
                print("Three strikes and your out!")
                sys.exit(-1)
            filename = Path(askopenfilename(filetypes=[("CSV files","*.csv")]))
            break
        except TypeError:
            badcount += 1
            print(f"bad filename, try again")
         
    return filename
 
 
if __name__ == '__main__':
    read_csv_file(get_filename())
I have tried to code this project in Python, but after three weeks I just have 10 lines of code..... I just don't know where to start I guess.

CSV file:https://ibb.co/5rqR1YQ
I couldn't upload a .csv file, so instead I have added the picture above.

The amounts of the expenses are examples, so I haven't spent €986,- euros at the swimming pool Big Grin

Hopefully someone can help!
Larz60+ write Dec-13-2020, 12:40 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

You should avoid using links as many members will not follow.
Reply


Messages In This Thread
Analyzing yearly expenses (CSV file) from debit card - by Python_User - Dec-13-2020, 02:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  create 10 yearly blocks from time series using pandas Staph 1 2,005 Jul-23-2019, 12:01 PM
Last Post: Malt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020