chrisis
chrisis

Reputation: 119

Delete square brackets in the CSV fie

I plot the results from python to CSV file. Unfortunately, the data plotted on the CSV file is difficult to edit. In fact each cell of Excel contains a data wrapped by square brackets. How would it be possible to delete the square brackets in the CSV file?

Here below you can find the code.

a=[[1.5458, 1.2585, 3.5687]]
S=(["S"], np.round(a,3), {' [MPa]'})
with open('Output.csv', 'w', newline='') as dest:
    thewriter = csv.writer(dest, delimiter=',')
    thewriter.writerows(a)

The output the I would like to get in the CSV file is the following one:

1.5458 1.2585 3.5687

Each number appears in a single cell of Excel.

Upvotes: 0

Views: 446

Answers (1)

drHodge
drHodge

Reputation: 76

Excel can be a bit picky when opening flat text files such as CSV. Sometimes it will automatically place items into separate columns other times it won't. It seems the last setting used on "Text to columns" feature "sticks" until you close Excel.

Close all your open Excel windows then reopen the file.

Also just open the file in notepad to check that it looks ok. Don't allow the complexity of everything Excel does to complicate things. Sorry this is an answer and not a comment, I am new to this site and don't have enough points to comment yet :-(

Upvotes: 1

Related Questions