Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh: Column DataSource part giving error

Tags:

python

bokeh

I am trying to create an interactive bokeh plot that holds multiple data and I am not sure why I am getting the error

ValueError: expected an element of ColumnData(String, Seq(Any)),got {'x': 6.794, 'y': 46.8339999999999, 'country': 'Congo, Dem. Rep.', 'pop': 3.5083789999999997, 'region': 'Sub-Saharan Africa'}

source = ColumnDataSource(data={
'x'       : data.loc[1970].fertility,
'y'       : data.loc[1970].life,
'pop'     : (data.loc[1970].population / 20000000) + 2,
'region'  : data.loc[1970].region,

})

I have tried two different data sets by importing data from excel and have been running out of issues on exactly why this happening.

enter image description here

like image 596
Siddharth Kulkarni Avatar asked Oct 26 '25 06:10

Siddharth Kulkarni


1 Answers

As the name suggests, the ColumnDataSource is a data structure for storing columns of data. This means that the value of every key in .data must be a column, i.e. a Python list, a NumPy array, or a Pandas series. But you are trying to assign plain numbers as the values, which is what the error message is telling you:

I am trying to create an interactive bokeh plot that holds multiple data and I am not sure why I am getting the error

expected an element of ColumnData(String, Seq(Any))

This is saying acceptable, expected values are dicts that map strings to sequences. But what you passed is clearly not that:

got {'x': 6.794, 'y': 46.8339999999999, 'country': 'Congo, Dem. Rep.', 'pop': 3.5083789999999997, 'region': 'Sub-Saharan Africa'}

The value for x for instance is just the number 6.794 and not an array or list, etc.

like image 71
bigreddot Avatar answered Oct 29 '25 06:10

bigreddot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!