close

[Solved] Bokeh: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Bokeh: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Bokeh: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’ Error Occurs?

Today I get the following error Bokeh: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’ in python.

How To Solve Bokeh: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’ Error ?

  1. How To Solve Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist' Error ?

    To Solve Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist' Error I solved the problem by first extracting the relevant columns from the dataframe.

  2. Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist'

    To Solve Bokeh: AttributeError: 'DataFrame' object has no attribute 'tolist' Error I solved the problem by first extracting the relevant columns from the dataframe.

Solution 1

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)

Solution 2

You are using tolist incorrectly. You want: .values followed by tolist()

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

For the above dataframe, to get your X and Y values as a list you can do:

tsneY_data = df['tsneY'].values.tolist()
>> [20.740931, 18.478468, 22.948167, 15.7389541]

tsneX_data = df['tsneX'].values.tolist()
>> [53.828863, 57.816909, 55.913429, 56.603005]

As you have tried to set this to the column of a new dataframe, you can do:

new_data = pd.DataFrame()
new_data['tsneY'] = df['tsneY'].values.tolist()

> new_data
       tsneY
0  20.740931
1  18.478468
2  22.948167
3  15.738954

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read