感谢您的帮助!!!!我快到了! 我有一组数据,我正在尝试绘制它,现在只是针对顺序整数,后来一旦我有这个工作,时间。
for a in Data['result'][:1]: #only print the first result in the list
#print a['value']
Data_clean = a['value'].replace('0,','0.')
Data_list = Data_clean.split(',')
T2 = [map(float, x) for x in Data_list] #turn string into integer so that it
#can be graphed
print T2
但它收到以下错误
T2 = [map(float, x) for x in Data_list]
ValueError: could not convert string to float:
Data_list看起来像这样
[u'-0.04149', u'-0.03866', u'-0.02914', u'-0.02319', u'-0.02027', u'-0.00234', u'0.00564', u'0.01269', u'0.02852', u'0.04648', u'0.05709', u'0.06261', u'0.07325', u'0.08223', u'0.08665']
答案 0 :(得分:3)
如果我理解你的目标你试图将它转换成一个bad.manner中的浮点数(不是整数),比如混合策略,你可以这样做:
T2 = map(float, Data_list)
#or
T2 = [float(x) for x in Data_list]
这就是你想要的吗?