Dec-13-2020, 02:24 PM
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 tried starting this project with open and edit a CSV file using the following code:
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
Hopefully someone can help!
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
- 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 Big Grin](https://python-forum.io/images/smilies/biggrin.png)
Hopefully someone can help!