converting string to float
Hello,
I am having troubles writing a python script. Specifically, I have a string of numbers and want to replace the word ''zero'' with the integer 0. I then want to cover this string into float values. I used data.replace, and as such had to put "" around the 0 - if not there is an error as it expects a character buffer object. Am I right in saying that I can strip the "" from the 0 before converting to a float?
for data in inFile: data = data.replace ("zero", "0") data = map(float,data.strip('"')) ValueError: could not convert string to float: s
Many thanks.
• 2,252 views
•
link
0 answers
No answers yet.
Log in to answer this question.
That's not a bioinformatics question but pure programming/coding, is it? Would be best suited for a _search_ on stackoverflow, e.g.: http://stackoverflow.com/questions/379906/parse-string-to-float-or-int
Hello a.rex!
We believe that this post does not fit the main topic of this site.
This is a programming question. Please search/ask stackoverflow.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!
In addition, you should read error messages carefully:
ValueError: could not convert string to float: s. Obviously, your data contains a string that cannot be converted, e.g. 's'.Sorry about this! I am a relatively new user of BioStars, I find it very useful for my bioinformatics learning. I realise now that this particular question was out of theme with the website.