I want to write data into a .csv file using python as float values. everytime I try to do it using the writerow function of the csv module it writes into the csv file but in quotes, rendering it as a string. I also cannot use float() function since the data acquires is in a list. Thanks in advance
Add a comment
|
1 Answer
I believe this is correct behaviour. From wiki 'Comma-separated values':
Standardization
Any field may be quoted (with double quotes).
EDIT
To avoid quoting u can set quoting=csv.QUOTE_NONE in your csv writer. Working example for Python 3.5.2:
import csv
with open('eggs.csv', 'w', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_NONE)
spamwriter.writerow([str(1.1112233), str(1.3355)])
egg.csv
1.1112233,1.3355
3 Comments
Dragon
thanks for the response. how can i remove the quotes appearing automatically in csv file?
wpedrak
I extended my answer. It's good idea to look at: docs.python.org/3/library/csv.html#csv.QUOTE_NONE and stackoverflow.com/questions/23882024/… aswell.
Dragon
Thanx for all ur responses but I got over with it by using the np.genfromtxt function, and setting the delimiters and the deletechars