繁体   English   中英

如何更新此 Bokeh ColumnDataSource?

[英]How to update this Bokeh ColumnDataSource?

我有以下数据框: 在此处输入图像描述

我想填充 Bokeh ColumnDataSource

# Data Container
source = ColumnDataSource(dict(
    time=[],
    open=[],
    high=[],
    low=[],
    last=[],
    volume=[],
    numberoftrades=[],
    bidvolume=[],
    askvolume=[],
    candle_body_fill_color=[],
    candle_body_line_color=[],
    candle_wick_color=[]
))

# Create a new data-container.
new_data = dict(
    time=range_df.datetime,
    open=range_df.open,
    high=range_df.high,
    low=range_df.low,
    last=range_df.last,
    volume=range_df.volume,
    numberoftrades=range_df.numberoftrades,
    candle_body_fill_color=range_df.candle_color,
    candle_body_line_color=range_df.candle_color,
    candle_wick_color=range_df.candle_color
)

# Update the data container.
source.data = new_data

但我收到了这个错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-268-48250bd1dfa0> in <module>
     30 
     31 # Update the data container.
---> 32 source.data = new_data

(bunch of other stack info)

ValueError: expected an element of ColumnData(String, Seq(Any)), got {'time': 0     2021-02-12 20:01:00
1     2021-02-12 20:02:00
2     2021-02-12 20:03:00
3     2021-02-12 20:04:00
4     2021-02-12 20:05:00
              ...        
99    2021-02-12 21:55:00
100   2021-02-12 21:56:00
101   2021-02-12 21:57:00
102   2021-02-12 21:58:00
103   2021-02-12 21:59:00

(and it just goes on and on to list my data frame bits)

使用它解决了这个问题:

# Create a new data-container.
new_data = dict(
    time=range_df['datetime'],
    open=range_df['open'],
    high=range_df['high'],
    low=range_df['low'],
    last=range_df['last'],
    volume=range_df['volume'],
    numberoftrades=range_df['numberoftrades'],
    candle_body_fill_color=range_df['candle_color'],
    candle_body_line_color=range_df['candle_color'],
    candle_wick_color=range_df['candle_color'],
)

不知道为什么我们不能使用. 符号了。 我敢肯定,以前曾经工作过。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM