title: Python saving data values to a csv
body: <p>Now this program reads data from a csv, sums the values per day, and calculates the cumulative values. In the next part, I want it to save the data to a new csv file.</p>
  <pre><code>import csv
  from collections import defaultdict, OrderedDict
  
  
  def convert(data):
      try:
          return int(data)
      except ValueError:
          return 0
  
  
  with open('Montdata1.csv', 'r') as file1:
          read_file = csv.reader(file1, delimiter=';')
          delheader = next(read_file)
          data = defaultdict(int)
          for line in read_file:
              valuedata = max(0, sum([convert(i) for i in line[1:5]]))
              data[line[0].split()[0]] += valuedata
  
          for key in OrderedDict(sorted(data.items())):
              print('{} {}'.format(key, data[key]))
          print(&quot;&quot;)
          previous_values = []
          for key, value in OrderedDict(sorted(data.items())).items():
              print('{} {}'.format(key, value + sum(previous_values)))
              previous_values.append(value)
  </code></pre>
  <p>It should be that in the column is the date, and in the second is the values. So it would be something like this:
  <a href="https://i.stack.imgur.com/Vmt43.png" rel="nofollow noreferrer">Example picture</a></p>
  <p>I have tried the following code, but it doesn't do anything:</p>
  <pre><code>with open('Datasave.csv', 'w', newline='') as csvfile:
      spamreader = csv.reader(csvfile, delimeter= ' ')
      for row in spamreader:
          print(', '.join(row))
  </code></pre>
  <p>Hope for some help<br />
  The data file as csv: <a href="https://files.fm/u/2vjppmgv" rel="nofollow noreferrer">https://files.fm/u/2vjppmgv</a><br />
  Data file in pastebin <a href="https://pastebin.com/Tw4aYdPc" rel="nofollow noreferrer">https://pastebin.com/Tw4aYdPc</a></p>