0
我有一個列表從SQL輸出看起來像這樣如何解析包含decimal和datetime.datetime的列表?
[(Decimal('264'), datetime.datetime(2012, 11, 1, 0, 0)), (Decimal('445812776'), datetime.datetime(2012, 12, 1, 0, 0)), (Decimal('545942604'), datetime.datetime(2013, 1, 1, 0, 0))]
我要繪製圖表使用matplotlib與x作爲日期時間和y爲對應的十進制來。
對於我試圖把它們分割兩個列表一個含小數和其他含日期時間,但我不能分析它,我想這
def convertTupletoString(s):
return str(list(s)).strip('[]').strip('\'')
t=[]
d=[]
suppose list is x
for i in list(x):
s = convertTupletoString(i)
x = s.find(",")
traffic = float(s[:x])
t.append(traffic)
date = datetime(s[x+1:])
d.append(date)
pyplot.plot(t,d)
我越來越不能轉換爲浮動錯誤,也無法轉換爲日期時間。 有人可以幫忙嗎?