unicode - Python BeautifulSoup string to float -
i have downloaded data set in xml format online webpage. have extracted values tag using beautifulsoup library of python. gives me unicode values.
graphs = soup.graphs c = 0 q in graphs: name = q['title'] data = {} r in graphs.contents[c]: print float(str(unicode(r.string))) data[r['xid']] = unicode(r.string) c = c + 1 result[name] = [data[k] k in key]
the source http://charts.realclearpolitics.com/charts/1171.xml
and want make r.string float type
so did
print float(str(unicode(r.string))) print float(unicode(r.string))
but met err
file "<ipython-input-142-cf14a8845443>", line 73 print float(unicode(r.string))) ^ syntaxerror: invalid syntax
how do?
first error imbalanced round brackets.
print float(str(unicode(r.string)))) ^ 4th here
second error, check value whether none or not before making operation. otherwise you'll error valueerror: not convert string float: none
so fix be:
if(r.string != none): print float(str(unicode(r.string)))
Comments
Post a Comment