Home > Enterprise >  CSV file in Python row
CSV file in Python row

Time:07-06

Why I am getting the space after one row and it is moving onto third row, when I write the code to open a CSV file in excel?

enter image description here

I have used the code below.

import csv

with open("self_taught.csv", "w") as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=",")
    spamwriter.writerow(["one", "two", "three"])
    spamwriter.writerow(["four", "five", "six"])

CodePudding user response:

Use newline="" when open csv by python.

EX:

with open(pathToFile, newline='') as f:
 ...
  • Related