【问题标题】:python data visualization bokehpython数据可视化散景
【发布时间】: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


【解决方案1】:

我用过

df.femaleliteracy = df.femaleliteracy.astype(float) 
df.fertility = df.fertility.astype(float) 

对于新手来说,请务必注意列类型...

从对象类型转换为浮点数,现在情节正在运行......非常感谢......!!!

另一个问题与 female_literacy 被用于之前对 figure() 的函数调用有关......重新启动内核解决了这个问题!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 2019-11-30
    • 2019-03-18
    • 1970-01-01
    • 2013-11-01
    • 2020-08-01
    • 1970-01-01
    相关资源
    最近更新 更多