我从Sqlite的Plotting系列中得到了一个问题(我尝试了2小时没有成功的不同解决方案)。
我的SQL声明:
p2 = sql.read_sql('select PCE,DT, VALUE_DEMANDE - VALUE_FORCAST as FC_ERROR FROM PCE GROUP BY PCE,DT_COMPUTE_FORCAST', cnx)
结果确定:
PCE DT FC_ERROR
0 TAG1 01/01/2015 00:00 3.573
1 TAG1 01/01/2015 01:00 3.514
..............................................
2 TAG2 01/01/2015 00:00 2.573
3 TAG2 01/01/2015 01:00 1.514
..............................................
2 TAG3 01/01/2015 00:00 6.573
3 TAG3 01/01/2015 01:00 4.514
我想将线条图(x轴:DT)作为http://pandas.pydata.org/pandas-docs/stable/visualization.html中的第二个图表 我试着用:
df = pd.DataFrame({'Error' :p2['FC_ERROR']},columns=list({'TAG1','TAG2','TAG3'}))
df.index = p2['DT']
ax=df.plot(lw=0.5,colormap='jet',marker='+',markersize=2,title='Time series Previsions / Reel')
ax=set_xlabel("Periode")
ax=set_ylabel("Value en Gwh")
如何从同一列中的数据生成columns = list? 我应该制作pd.series(...
谢谢
好的家伙我试试
p2 = sql.read_sql('select PCE,DT_COMPUTE_FORCAST, VALUE_DEMANDE,VALUE_FORCAST ,VALUE_DEMANDE - VALUE_FORCAST as FC_ERROR FROM PCE', cnx)
for name, groupe in p2.groupby('PCE'):
print name
df = pd.DataFrame({'Pce' : groupe['PCE'].values,'FE' :groupe['FC_ERROR'].values})
df.index = groupe['DT_COMPUTE_FORCAST']
df = pd.DataFrame(groupe['FC_ERROR'].values, index=groupe['DT_COMPUTE_FORCAST'], columns=set(name))
plt.figure()
df.plot()
'for name'循环工作(并且比我认为的更快)我得到(demo)2个字符串元素。 当我启动脚本时,python告诉我:
for name, groupe in p2.groupby('PCE'):
print name
df = pd.DataFrame({'Pce' : groupe['PCE'].values,'FE' :groupe['FC_ERROR'].values})
df.index = groupe['DT_COMPUTE_FORCAST']
df = pd.DataFrame(groupe['FC_ERROR'].values, index=groupe['DT_COMPUTE_FORCAST'], columns=set(name))
plt.figure()
df.plot()
A12250I2
A12250T2
Traceback (most recent call last):
File "<ipython-input-138-73fb44bbbf67>", line 9, in <module>
df = pd.DataFrame(groupe['FC_ERROR'].values, index=groupe['DT_COMPUTE_FORCAST'], columns=set(name))
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 239, in __init__
copy=copy)
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 399, in _init_ndarray
return create_block_manager_from_blocks([values.T], [columns, index])
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 3534, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 3515, in construction_error
passed,implied))
ValueError: Shape of passed values is (1, 22509), indices imply (6, 22509)
如果有人可以给我一个提示,我会被困住?
以下脚本在绘图上绘制每个数据框(来自循环)。
for name, groupe in p2.groupby('PCE'):
df = pd.DataFrame({str(name) : groupe['FC_ERROR'].values})
df.index=groupe['DT_COMPUTE_FORCAST']
df.plot()
我想在1张图表上绘制所有数据框!你有提示吗?