1

Basically currently my program reads the Data file (electric info), sums the values up, and after summing the values, it changes all the negative numbers to 0, and keeps the positive numbers as they are. The program does this perfectly. This is the code I currently have:

import csv
from datetime import timedelta
from collections import defaultdict


def convert(item): 
    try:
        return float(item)
    except ValueError:
        return 0

sums = defaultdict(list)

def daily():
    lista = []
    with open('Data.csv', 'r') as inp:
        reader = csv.reader(inp, delimiter = ';')
        headers = next(reader)
        for line in reader: 
            mittaus = max(0,sum([convert(i) for i in line[1:-2]])) 
            lista.append()
            #print(line[0],mittaus) ('#'only printing to check that it works ok)
daily()

My question is: How can I save the data to lists, so I can use them, and add all the values per day, so should look something like this:

1.1.2016;358006
2.1.2016;39
3.1.2016;0 ...
8.1.2016;239143

After had having these in a list (to save later on to a new data file), it should calculate the cumulative values straight after, and should look like this:

1.1.2016;358006
2.1.2016;358045
3.1.2016;358045...
8.1.2016;597188 

Having done these, it should be ready to write these datas to a new csv file.
Small peak what's behind the Data file: https://pastebin.com/9HxwcixZ [It's actually divided with ';' , not with ' ' as in the pastebin]
The data file: https://files.fm/u/yuf4bbuk

I have clarified the questions, so you might have seen me ask before. These should be done without external libraries. I hope to find some help.

Koppis
  • 109
  • 8
  • Possible duplicate of [How to find the cumulative sum of numbers in a list?](https://stackoverflow.com/questions/15889131/how-to-find-the-cumulative-sum-of-numbers-in-a-list) – ahota Nov 20 '18 at 00:10
  • Do you want to sum all the row? – Geancarlo Murillo Nov 20 '18 at 00:27
  • I want to have every days value in it's own row. So 1.1.2016[value] in it's own row, 2.1.2016[value] in own row etc. – Koppis Nov 20 '18 at 12:05

0 Answers0