散景:AttributeError:'DataFrame'对象没有属性'tolist' [英] Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist'

查看:105
本文介绍了散景:AttributeError:'DataFrame'对象没有属性'tolist'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是熊猫和散景的新手,我正试图从熊猫数据框中创建散点图.但是,我不断收到以下错误:

I am new to pandas and bokeh and I am trying to create a scatter plot from a pandas dataframe. However, I keep getting the following error:

new_data[colname] = df[colname].tolist()
AttributeError: 'DataFrame' object has no attribute 'tolist' 

使用bokeh中的虚拟数据(从bokeh.sampledata.iris导入花作为数据),散点效果很好.

Using the dummy data from bokeh (from bokeh.sampledata.iris import flowers as data) the scatter works fine.

   type   tsneX      tsneY      +50.000 columns
0  A      53.828863  20.740931  
1  B      57.816909  18.478468  
2  A      55.913429  22.948167  
3  C      56.603005  15.738954 


scatter = Scatter(df, x='tsneX', y='tsneY',
                  color='type', marker='type',
                  title='t-sne',
                  legend=True)

我没有使用tolist(),但是Bokeh的Scatter()确实会产生以下错误.

I'm not using the tolist(), but the Scatter() of Bokeh does and produces the error below.

推荐答案

我通过首先从数据框中提取相关列来解决了这个问题.

I solved the problem by first extracting the relevant columns from the dataframe.

df = df.loc[:, ('type', 'tsneX', 'tsneY')

scatter = Scatter(df, x='tsneX', y='tsneY',
                  color='type', marker='type',
                  title='t-sne',
                  legend=True)

这篇关于散景:AttributeError:'DataFrame'对象没有属性'tolist'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆