使用plotly从多个csv文件中绘制一个图形

时间:2019-07-30 18:55:02

标签: python csv drop-down-menu plotly

我想使用图来创建一个交互式图表,并包括一个下拉菜单,以涵盖每周,每月,每季度和每年的商品价格指数。如何从这四个单独的csv文件中提取数据?

dfq=pd.read_csv('Quaterly_BoC Commodity Index.csv')
enter code here`dfm=pd.read_csv('Monthly_BoC Commodity Index.csv')
enter code here`dfy=pd.read_csv('Annual_BoC Commodity Index.csv')


dfw=pd.read_csv('Weekly BoC Commodity Index.csv')

## I started with weekly file
trace_BCPI=go.Scatter( x=list(dfw.date ),
                      y=list(dfw.BCPI), 
                      name='BCPI',  line=dict(color='#33CFA5'))

trace_BCPI_avg= go.Scatter (x=list(dfw.date),
                            y=[dfw.BCPI.mean()]*len(dfw.date),
                            name='BCPI average',
                            visible= False)
BCPI_annotations=[dict(x='2016-03-01',
                       y=dfw.BCPI.mean(),
                       xref='x', yref='y',
                       text='BCPI Average:<br>'+str(dfw.BCPI.mean())),
                  dict(x=dfw.BCPI.idxmax(),
                       y=dfw.BCPI.max(),
                       xref='x', yref='y',
                       text='BCPI Max:<br>'+str(dfw.BCPI.max())),
                 dict(x=dfw.BCPI.idxmin(),
                       y=dfw.BCPI.min(),
                       xref='x', yref='y',
                       text='BCPI Min:<br>'+str(dfw.BCPI.min()),
                    )]



layout=dict(title='Bank of Canada commodity price index', showlegend= False)
fig = dict(data=data, layout=layout)

iplot(fig)

## now I want to add a dropdown menu to include stats from monthly, quarterly and annual csv file. Any suggestion? thank you!

0 个答案:

没有答案