Python How do I sum the data values












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.










share|improve this question























  • Possible duplicate of How to find the cumulative sum of numbers in a list?

    – ahota
    Nov 20 '18 at 0:10











  • Do you want to sum all the row?

    – Geancarlo Murillo
    Nov 20 '18 at 0: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
















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.










share|improve this question























  • Possible duplicate of How to find the cumulative sum of numbers in a list?

    – ahota
    Nov 20 '18 at 0:10











  • Do you want to sum all the row?

    – Geancarlo Murillo
    Nov 20 '18 at 0: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














1












1








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.










share|improve this question














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.







python python-3.x csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 0:06









KoppisKoppis

386




386













  • Possible duplicate of How to find the cumulative sum of numbers in a list?

    – ahota
    Nov 20 '18 at 0:10











  • Do you want to sum all the row?

    – Geancarlo Murillo
    Nov 20 '18 at 0: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



















  • Possible duplicate of How to find the cumulative sum of numbers in a list?

    – ahota
    Nov 20 '18 at 0:10











  • Do you want to sum all the row?

    – Geancarlo Murillo
    Nov 20 '18 at 0: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

















Possible duplicate of How to find the cumulative sum of numbers in a list?

– ahota
Nov 20 '18 at 0:10





Possible duplicate of How to find the cumulative sum of numbers in a list?

– ahota
Nov 20 '18 at 0:10













Do you want to sum all the row?

– Geancarlo Murillo
Nov 20 '18 at 0:27





Do you want to sum all the row?

– Geancarlo Murillo
Nov 20 '18 at 0: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





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






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384394%2fpython-how-do-i-sum-the-data-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384394%2fpython-how-do-i-sum-the-data-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith