[SOLVED] Array in a specific format in csv file using Python


I am trying to save the array inv_r in a specific format in a csv file. The current and the desired formats are attached.

import numpy as np
import csv

data = [inv_r]

with open('inv_r.csv', 'w') as f:
    writer = csv.writer(f)

    # write the data

The current format is

enter image description here

The desired format is

enter image description here


You need to remove the zip, first of all, so that each element get its own cell.

To remove the blank lines between each row, you need to add newline='' to the open call. See the footnote in the documentation for the csv library here for an explanation as to why this is necessary.

Answered By – ishaan

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *