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.

1
  • post the final csv content with concrete field separator Commented Aug 20, 2019 at 6:23

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

its throwing an error TypeError: a bytes-like object is required, not 'str'
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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.