簡體   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