I am new to Python, Bokeh and coding in general so please forgive me if I have done something dumb…
I have created a dataframe of zeroes using numpy and then I’m trying to pass it into a ColumnDataSource object for manipulation in Bokeh. The fact it is zeroes is not important; any time I try and do this using a dataframe created via a numpy array, I get the same error:
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
df = pd.DataFrame(np.zeros((8,8)))
source = ColumnDataSource(df)
The final line throws this error:
ValueError: expected an element of ColumnData(String, Seq(Any)), got {‘index’: array([0, 1, 2, 3… (it then prints out the entire dataframe)
On Wednesday, March 20, 2019 at 2:54:58 PM UTC, Sam Farrington wrote:
Hello,
I am new to Python, Bokeh and coding in general so please forgive me if I have done something dumb…
I have created a dataframe of zeroes using numpy and then I’m trying to pass it into a ColumnDataSource object for manipulation in Bokeh. The fact it is zeroes is not important; any time I try and do this using a dataframe created via a numpy array, I get the same error:
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
df = pd.DataFrame(np.zeros((8,8)))
source = ColumnDataSource(df)
The final line throws this error:
ValueError: expected an element of ColumnData(String, Seq(Any)), got {‘index’: array([0, 1, 2, 3… (it then prints out the entire dataframe)
It will NOT work if the column headings are integer types (which I think is what you’re getting by default here). You could avoid explicitly naming your columns by generating a list of ints and converting:
df = pd.DataFrame(data=np.zeros((8,8)), columns=[str(i) for i in np.arange(0, 8)])
``
Try it out.
···
On Wednesday, March 20, 2019 at 9:54:58 AM UTC-5, Sam Farrington wrote:
Hello,
I am new to Python, Bokeh and coding in general so please forgive me if I have done something dumb…
I have created a dataframe of zeroes using numpy and then I’m trying to pass it into a ColumnDataSource object for manipulation in Bokeh. The fact it is zeroes is not important; any time I try and do this using a dataframe created via a numpy array, I get the same error:
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
df = pd.DataFrame(np.zeros((8,8)))
source = ColumnDataSource(df)
The final line throws this error:
ValueError: expected an element of ColumnData(String, Seq(Any)), got {‘index’: array([0, 1, 2, 3… (it then prints out the entire dataframe)
This is exactly correct. Just to state it in other terms: A CDS maps *string* column names to lists/arrays/series of data. It is not possible to have non-string column names (in fact I am surprised to know Pandas allows this).
I am new to Python, Bokeh and coding in general so please forgive me if I have done something dumb...
I have created a dataframe of zeroes using numpy and then I'm trying to pass it into a ColumnDataSource object for manipulation in Bokeh. The fact it is zeroes is not important; any time I try and do this using a dataframe created via a numpy array, I get the same error:
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
df = pd.DataFrame(np.zeros((8,8)))
source = ColumnDataSource(df)
The final line throws this error:
ValueError: expected an element of ColumnData(String, Seq(Any)), got {'index': array([0, 1, 2, 3... (it then prints out the entire dataframe)
It will NOT work if the column headings are integer types (which I think is what you’re getting by default here). You could avoid explicitly naming your columns by generating a list of ints and converting:
df = pd.DataFrame(data=np.zeros((8,8)), columns=[str(i) for i in np.arange(0, 8)])
``
Try it out.
On Wednesday, March 20, 2019 at 9:54:58 AM UTC-5, Sam Farrington wrote:
Hello,
I am new to Python, Bokeh and coding in general so please forgive me if I have done something dumb…
I have created a dataframe of zeroes using numpy and then I’m trying to pass it into a ColumnDataSource object for manipulation in Bokeh. The fact it is zeroes is not important; any time I try and do this using a dataframe created via a numpy array, I get the same error:
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
df = pd.DataFrame(np.zeros((8,8)))
source = ColumnDataSource(df)
The final line throws this error:
ValueError: expected an element of ColumnData(String, Seq(Any)), got {‘index’: array([0, 1, 2, 3… (it then prints out the entire dataframe)