简体   繁体   中英

Error displaying pandas dataframe in Google Colaboratory

I have a data analysis pipeline built in Google Colab python(3.6) notebook. Whenever I try to display the pandas(0.23.4) Data Frame inline I get the following error:

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

The only thing it seems to solve the problem is to create a new colab notebook. (file > new notebook). But even then it eventually ends up with the same issue after using it a while.

Also, important to note that the Data Frame works properly for calculations and accessing the values. It seems to be an issue displaying it.

df.head()

Results in:


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'

The expected results is to have the Data Frame displayed in a html table.

You could try to use IPython display (see number 3 from here )

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

Alternatively, add these 2 lines to your imports and you don't need display (explanation here )

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

df.head()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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