【发布时间】:2018-11-07 23:04:50
【问题描述】:
你好世界上聪明的程序员
我有 2 个问题 我有这样的数据集:
第一个也是主要的问题是他打印了一些奇怪的情节,像这样:
与我用作参考的原始图相比毫无意义 ->
第二个问题是他正在打印一些错误信息->
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', ...)]
我的代码是这样的:
# 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)
******编辑*************
******************再次编辑****************************
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)
【问题讨论】:
-
您确定此处显示的代码会重现错误吗?这些错误提到了您的代码中没有的“female_literacy”。
-
Country 后面有空格,先试试删掉..
df.columns = ['Country '] -
是的,我已经删除了空间,保持不变...不过谢谢...
-
代码中的
female_literacy在哪里? -
到处都没有
female_literacy...我不知道他从哪里拿来的 !!!!!!???
标签: python data-visualization bokeh