0

I saw this question asked a few times and used the solutions I found, (such as Writing a Python list of lists to a csv file). However, for some reason, it did not work for me.

Here is my code:

import numpy as np
import csv

data = np.array([[1,2,3],[4,5,6]])

with open("~test.csv", "wb") as f:
    writer = csv.writer(f,delimiter=',')
    writer.writerows(data)
f.close()    

I know that a numpy array can and should be treated (in this case) as a list of lists.

When I open the csv, cell A1 contains "1,2,3" and A2 contains "4,5,6". I would like the comma to correclty be used as the delimiter so that all 6 values are distributed over the range [A1:C2].

Could this be a problem with my Excel settings?

Community
  • 1
  • 1
user2758991
  • 7
  • 1
  • 4

1 Answers1

0

It worked for me; when you load the CSV file into Excel, are you specifying that the values are separated by commas?

Based on your description and code, my best guess is that your settings in Excel are causing it to load incorrectly.

Ryan
  • 3,555
  • 1
  • 22
  • 36