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
Asked
Active
Viewed 3,224 times
0

whatdoyouNeedFromMe
- 105
- 11

Dragon
- 1,194
- 17
- 24
1 Answers
0
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

wpedrak
- 667
- 7
- 17
-
thanks for the response. how can i remove the quotes appearing automatically in csv file? – Dragon Jun 09 '17 at 10:09
-
I extended my answer. It's good idea to look at: https://docs.python.org/3/library/csv.html#csv.QUOTE_NONE and https://stackoverflow.com/questions/23882024/using-python-csv-writer-without-quotations aswell. – wpedrak Jun 09 '17 at 11:23
-
Thanx for all ur responses but I got over with it by using the np.genfromtxt function, and setting the delimiters and the deletechars – Dragon Jun 09 '17 at 17:22