1

As per the heading of my question, What I have si a variable which contains an array of values like

1
4
3
5
3
5
3
5
4
5
3
6
4
6

the values are stored in a variable name datawindow4 Now what I want is that I want to save these values in a CSV format. so that I can use it for further purpose. How can I pursue that? is there any way? Please suggest. Any help is appreciated.

Chempooro
  • 415
  • 1
  • 7
  • 24

3 Answers3

1

if your variable is a 1d list containing numbers:

import csv
datawindow4 = [1,2,3,4]
with open('new.csv', 'w') as f:
    for d in datawindow4:
        f.write(str(d))
        f.write("\n")

output:

1
2
3
4
SM Abu Taher Asif
  • 2,221
  • 1
  • 12
  • 14
0

A CSV file is just a text file with a delimiter to separate value.

You can simply open a file, iterate your value and puts them into your file, close your file

or use the library csv : here the question has already been asked

jgengo
  • 103
  • 1
  • 1
  • 9
0
import csv

with open("your_csv.csv", "wb") as csv_file:
        writer = csv.writer(csv_file, delimiter=',')
        for line in your_array:
            writer.writerow(line)
Kostas Charitidis
  • 2,991
  • 1
  • 12
  • 23