I have written a file in Python that takes data from a database and writes these in a CSV file, but some data are formatted in a wrong way. When I open the .csv file they appear with more “.” points.
I print these data (longitude and altitude) before write and they are correct.
What happens when I write these using writerow
:
then the CSV written is like this with triple points. Why?
Here is the code:
with open(f"./DataBaseCsv/Selezione_Biciclette.csv", mode="w") as
csvWRFile:
fieldnames = ["Città" , "Provincia" , "Nome" , "Tipo" , "Longitudine" ,
"Latitudine"]
writer = csv.DictWriter(csvWRFile , fieldnames=fieldnames ,
delimiter=';' , doublequote = False)
writer.writeheader()
for singleList in dati:
print(f"Before WR long. {singleList[5] } lat. {singleList[6] }")
writer.writerow({"Città" : singleList[0] , "Provincia" :
singleList[1] , "Nome" : singleList[2] , "Tipo" : singleList[3] ,
"Longitudine" : singleList[5] , "Latitudine" : singleList[6] })
I’m expected that is a problem of formatting using writerow… but I don’t know.
Enrico Alessandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5