I was learning to write a .csv file. I ran the code of this site https://www.geeksforgeeks.org/writing-csv-files-in-python/
I ran the code and found that there is an extra row gap after each row which I don't want.
The code is as follows:
# Python program to demonstrate
# writing to CSV
import csv
# field names
fields = ['Name', 'Branch', 'Year', 'CGPA']
# data rows of csv file
rows = [ ['Nikhil', 'COE', '2', '9.0'],
['Sanchit', 'COE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'SE', '1', '9.5'],
['Prateek', 'MCE', '3', '7.8'],
['Sahil', 'EP', '2', '9.1']]
# name of csv file
filename = "university_records.csv"
# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(rows)
I am getting output as follows:
I want to get output something like this:
I need to write csv files for a very big dataset therefore it can't be done manually. I need inputs so that writing csv files can be coded. Thanking in advance!!