繁体   English   中英

在Google Colaboratory中显示pandas数据框时出错

[英]Error displaying pandas dataframe in Google Colaboratory

我有一个在Google Colab python(3.6)笔记本中构建的数据分析管道。 每当我尝试显示大熊猫(0.23.4)数据帧内联时,我会收到以下错误:

TypeError: init ()得到一个意外的关键字参数'max_rows'

它似乎解决问题的唯一方法是创建一个新的colab笔记本。 (文件>新笔记本)。 但即便如此,在使用它一段时间之后它最终也会遇到同样的问题。

此外,重要的是要注意数据框适用于计算和访问值。 这似乎是一个显示它的问题。

df.head()

结果是:


TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    336             method = get_real_method(obj, self.print_method)
    337             if method is not None:
--> 338                 return method()
    339             return None
    340         else:

2 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in _repr_html_(self)
    694         See Also
    695         --------
--> 696         to_html : Convert DataFrame to HTML.
    697 
    698         Examples

/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in to_html(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, bold_rows, classes, escape, max_rows, max_cols, show_dimensions, notebook, decimal, border, table_id)
   2035             Dictionary mapping columns containing datetime types to stata
   2036             internal format to use when writing the dates. Options are 'tc',
-> 2037             'td', 'tm', 'tw', 'th', 'tq', 'ty'. Column can be either an integer
   2038             or a name. Datetime columns that do not have a conversion type
   2039             specified will be converted to 'tc'. Raises NotImplementedError if

/usr/local/lib/python3.6/dist-packages/pandas/io/formats/format.py in to_html(self, classes, notebook, border)
    751             need_leadsp = dict(zip(fmt_columns, map(is_numeric_dtype, dtypes)))
    752 
--> 753             def space_format(x, y):
    754                 if (y not in self.formatters and
    755                         need_leadsp[x] and not restrict_formatting):

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

预期的结果是将数据框显示在html表中。

您可以尝试使用 IPython display (请参阅此处的数字3)

from IPython import display
display(df.head())

或者,将这两行添加到导入中,您不需要display此处说明)

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

df.head()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM