Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly giving error message "TypeError: __init__() got an unexpected keyword argument 'encoding'" - Python

I only came across Plotly yesterday, I'm trying to find a way to produce tables in a nice way, similar to producing charts in Matplotlib.

Initially I tried to use my own data, and kept getting the error message in the title. So I have copy and pasted the exact code from the plotly website and still get this error. Has anyone encountered this before? Does anyone have a solution. I get the feeling this isn't a simple problem with my code.

import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')

trace = go.Table(
    header=dict(values=list(df.columns),
                fill = dict(color='#C2D4FF'),
                align = ['left'] * 5),
    cells=dict(values=[df.Rank, df.State, df.Postal, df.Population],
               fill = dict(color='#F5F8FF'),
               align = ['left'] * 5))

data = [trace]
py.iplot(data, filename = 'pandas_table')

This is the code I have used, that results in the following error:

TypeError: __init__() got an unexpected keyword argument 'encoding'

If anyone has an alternative to plotly, where I could produce nice looking tables that would also be really helpful.

Many thanks

like image 378
top bantz Avatar asked Sep 23 '26 20:09

top bantz


1 Answers

Depends on your environment. If you're using notebooks, qgrid is a really nice tool for working with pandas dataframes but I don't know if it works in other environments.

Regarding the code, it works for me (again in a notebook environment) by changing

import plotly.plotly as py

for

import plotly.offline as py
py.init_notebook_mode(connected=False)

I tend to use offline plotly, which is standard in plotly 3.

like image 94
vlizana Avatar answered Sep 25 '26 08:09

vlizana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!