I am trying to read a Financial CSV with Python, and the data looks like this:
Company1;2018;12345;67890;
Company1;2019;34242;12313;
Company2;2018;12412;32423;
Company3;2017;12314;23554;
...
What I am searching for is a function that give me following result after reading this CSV:
Dict2 = {
Company1: { 2018: { Costs: 123, employes: 1231}
2019: { Costs: 231, employes: 1321}}
Company2: { 2019: { Costs: 123, employes: 1231}
Company3: { 2019: { Costs: 123, employes: 1231}
}
I am processing the CSV like this:
file2 = open(pfad_ordner + "\daten\standortdaten\FirmenBilanz.csv", "r")
reader = csv.reader(file2, delimiter =";")
Dict2 = {}
for row in reader:
Dict2[row[0]] = {"Jahr":row[2], "Ort":row[1], "Mitarbeiter_gewerblich": row[3]}
if i do it this way, python ignores the row with same company name. or lets better say, it updates the dictionary so only one row got stored per company key.