Hello there wise programmers of the world
I´m 2 issues I have my dataset like this:
The first and main issue is that he is printing some weird plots, like this:
Makes no sense in comparison with the original plot that I´m using as reference ->
The second issue is that he is printing some error messages ->
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: female_literacy [renderer: GlyphRenderer(id='1fb09ca6-67a9-47c6-a528-a01030829385', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: female_literacy [renderer: GlyphRenderer(id='4ed4e766-485c-409a-9d61-1e0fdbd81c62', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: femaleliteracy [renderer: GlyphRenderer(id='13f9c2a6-d8fc-49b2-909b-ddb50313f619', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: femaleliteracy [renderer: GlyphRenderer(id='379aabbe-feee-4324-9819-6a019b615991', ...)]
My code goes like this:
# Import row from bokeh.layouts
from bokeh.layouts import row
df = pd.read_csv('literacy_birth_rate.csv')
df.columns = ['Country ', 'Continent', 'femaleliteracy', 'fertility', 'population']
source = ColumnDataSource(df)
# Create the first figure: p1
p1 = figure(x_axis_label='fertility (children per woman)', y_axis_label='femaleliteracy (% population)')
# Add a circle glyph to p1
p1.circle(x='fertility', y='femaleliteracy', source=source)
# Create the second figure: p2
p2 = figure(x_axis_label='population', y_axis_label='femaleliteracy (% population)')
# Add a circle glyph to p2
p2.circle(x='population',y='femaleliteracy', source=source)
# Put p1 and p2 into a horizontal row: layout
layout = row(p1,p2)
# Specify the name of the output_file and show the result
output_file('fert_row.html')
show(layout)
******edited***********
***************editing again***********************
Import row from bokeh.layouts
from bokeh.layouts import row
from bokeh.plotting import figure
df = pd.read_csv('literacy_birth_rate.csv')
df.columns = ['Country', 'Continent', 'femaleliteracy', 'fertility', 'population']
df.dropna(inplace=True)
source = ColumnDataSource(df)
# Create the first figure: p1
p1 = figure(x_axis_label='fertility (children per woman)', y_axis_label='femaleliteracy (% population)')
# Add a circle glyph to p1
p1.circle(x='fertility', y='femaleliteracy', source=source)
# Create the second figure: p2
p2 = figure(x_axis_label='population', y_axis_label='femaleliteracy (% population)')
# Add a circle glyph to p2
p2.circle(x='population',y='femaleliteracy', source=source)
# Put p1 and p2 into a horizontal row: layout
layout = row(p1,p2)
# Specify the name of the output_file and show the result
output_file('fert_row.html')
show(layout)
I´ve used
df.femaleliteracy = df.femaleliteracy.astype(float)
df.fertility = df.fertility.astype(float)
For newbies it´s important to indicate pay attention to column types ...
to convert from object type to float, and now the plot is working... thanks a lot ... !!!
the other problem was related to the fact that female_literacy
was being used in a prior function call to the figure()... restarting the kernel solved that !!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.