本文介绍了使用Bokeh/Widget/Callback过滤数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前我的数据集的格式为:Date, Currency, Price
,我正在货币级别进行过滤,然后使用它来生成图形.
Currently my data set is in the format: Date, Currency, Price
which I am filtering at Currency level and then using it to generate graphs.
我想改进它,以便使用Python小部件/下拉框完成所有过滤?
I want to improve it so that all the filtering is done using Python widget/Dropdown boxes?
我是Python/Bokeh的新手,所以我需要一些帮助.
I'm new to Python/Bokeh so I need some help.
Date Currency Price
1/1/2017 AUDUSD 1.01
2/1/2017 AUDUSD 1.02
3/1/2017 AUDUSD 1.03
1/1/2017 USDJPY 1.01
2/1/2017 USDJPY 1.02
3/1/2017 USDJPY 1.03
1/1/2017 CADUSD 1.01
2/1/2017 CADUSD 1.02
3/1/2017 CADUSD 1.03
推荐答案
#Creating CCyPair wise menu
menu = Select(options=['AUDUSD','USDJPY'], value='AUDUSD')
#Function for dataframe
def get_all_price_dataset(src,name):
df = src[(src.CCYPair == name) & (src.TYPE == 'Prices')].copy()
return df
# Function to update Plot
def update_plot(attrname, old, new):
newccy = menu.value
side = buysellmenu.value
datevalue = datemenu.value
src_data_table =
ColumnDataSource(get_all_dataset(Combined,newccy,side,datevalue))
DisplayData.data.update(src_data_table.data)
#On change in menu,function gets called.
menu.on_change('value', update_plot)
#Displaying Menu and Plot.
layout = layout([menu],
[plot])
curdoc().add_root(layout)
这篇关于使用Bokeh/Widget/Callback过滤数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!