故意给出错误消息“;TypeError:uuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;编码'"E;”python

故意给出错误消息“;TypeError:uuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;编码'"E;”python,python,pandas,plotly,plotly-python,Python,Pandas,Plotly,Plotly Python,我昨天才遇到Plotly,我正试图找到一种方法,以一种很好的方式生成表,类似于在Matplotlib中生成图表 起初,我尝试使用自己的数据,并不断在标题中获取错误消息。所以我复制并粘贴了plotly网站上的精确代码,但仍然得到了这个错误。以前有人遇到过这种情况吗?有人有解决办法吗。我觉得这不是我的代码的简单问题 import plotly.plotly as py import plotly.graph_objs as go import pandas as pd df = pd.read_c

我昨天才遇到Plotly,我正试图找到一种方法,以一种很好的方式生成表,类似于在Matplotlib中生成图表

起初,我尝试使用自己的数据,并不断在标题中获取错误消息。所以我复制并粘贴了plotly网站上的精确代码,但仍然得到了这个错误。以前有人遇到过这种情况吗?有人有解决办法吗。我觉得这不是我的代码的简单问题

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')
这是我使用的代码,导致以下错误:

TypeError:\uuuu init\uuuuuuuu()得到一个意外的关键字参数“encoding”

如果有人可以选择plotly,我可以在那里制作美观的表格,这也会非常有用


非常感谢

这取决于您的环境。如果你使用笔记本电脑,这是一个非常好的工具,用于处理熊猫数据帧,但我不知道它是否适用于其他环境

关于代码,它对我来说(同样在笔记本环境中)是通过改变

import plotly.plotly as py
为了


我倾向于使用离线plotly,这在plotly 3中是标准的。

它看起来像一个bug。如果您赶时间,迫不及待地等待修复,您可以执行以下操作:

打开
/usr/lib/python3/dist packages/simplejson/\uuuu init\uuuu.py
并在
转储方法中编辑'cls'变量,如下所示:
cls=jsonecoder

看起来是这样的:

    if cls is None:
        cls = JSONEncoder
    cls = JSONEncoder
    return cls(
        skipkeys=skipkeys, ensure_ascii=ensure_ascii,
        check_circular=check_circular, allow_nan=allow_nan, indent=indent,
        separators=separators, encoding=encoding, default=default,
        use_decimal=use_decimal,
        namedtuple_as_object=namedtuple_as_object,
        tuple_as_array=tuple_as_array,
        iterable_as_array=iterable_as_array,
        bigint_as_string=bigint_as_string,
        sort_keys=sort_keys,
        item_sort_key=item_sort_key,
        for_json=for_json,
        ignore_nan=ignore_nan,
        int_as_string_bitcount=int_as_string_bitcount,
        **kw).encode(obj)

基本上强制它使用默认的JSONECODER而不是Plotly编码器。另外,还要确保更改不会中断使用JSON的任何其他代码。它对我很有效,但肯定有更好的解决方案。

你好,mate,改为
导入plotly.offline作为py
,然后给文件名一个
。html
结尾对我很有效,非常感谢。我不使用笔记本,只使用pycharm,但我会看看qgrid,谢谢你的建议。
    if cls is None:
        cls = JSONEncoder
    cls = JSONEncoder
    return cls(
        skipkeys=skipkeys, ensure_ascii=ensure_ascii,
        check_circular=check_circular, allow_nan=allow_nan, indent=indent,
        separators=separators, encoding=encoding, default=default,
        use_decimal=use_decimal,
        namedtuple_as_object=namedtuple_as_object,
        tuple_as_array=tuple_as_array,
        iterable_as_array=iterable_as_array,
        bigint_as_string=bigint_as_string,
        sort_keys=sort_keys,
        item_sort_key=item_sort_key,
        for_json=for_json,
        ignore_nan=ignore_nan,
        int_as_string_bitcount=int_as_string_bitcount,
        **kw).encode(obj)