0

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the response. how can i remove the quotes appearing automatically in csv file?
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.
Thanx for all ur responses but I got over with it by using the np.genfromtxt function, and setting the delimiters and the deletechars

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.