I was trying to run this cell in the fourth notebook of the book :
#hide_output
im3_t = tensor(im3)
df = pd.DataFrame(im3_t[4:15,4:22])
df.style.set_properties(**{‘font-size’:‘6pt’}).background_gradient(‘Greys’)
and got this error :
AttributeError Traceback (most recent call last)
/usr/lib/python3/dist-packages/IPython/core/formatters.py in call(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
→ 345 return method()
346 return None
347 else:
~/.local/lib/python3.10/site-packages/pandas/io/formats/style.py in repr_html(self)
381 Hooks into Jupyter notebook rich display system, which calls repr_html by
382 default if an object is returned at the end of a cell.
→ 383 “”"
384 if get_option(“styler.render.repr”) == “html”:
385 return self.to_html()
~/.local/lib/python3.10/site-packages/pandas/io/formats/style.py in to_html(self, buf, table_uuid, table_attributes, sparse_index, sparse_columns, bold_headers, caption, max_rows, max_columns, encoding, doctype_html, exclude_styles, **kwargs)
1306 Whether to sparsify the display of a hierarchical index. Setting to False
1307 will display each explicit level element in a hierarchical key for each
→ 1308 column. Defaults to pandas.options.styler.sparse.columns
value.
1309
1310 … versionadded:: 1.4.0
~/.local/lib/python3.10/site-packages/pandas/io/formats/style_render.py in _render_html(self, sparse_index, sparse_columns, max_rows, max_cols, **kwargs)
203 Renders the Styler
including all applied styles to HTML.
204 Generates a dict with necessary kwargs passed to jinja2 template.
→ 205 “”"
206 d = self._render(sparse_index, sparse_columns, max_rows, max_cols, " ")
207 d.update(kwargs)
~/.local/lib/python3.10/site-packages/pandas/io/formats/style_render.py in _render(self, sparse_index, sparse_columns, max_rows, max_cols, blank)
160 Also extends the ctx
and ctx_index
attributes with those of concatenated
161 stylers for use within _translate_latex
→ 162 “”"
163 self._compute()
164 dxs = []
~/.local/lib/python3.10/site-packages/pandas/io/formats/style_render.py in _compute(self)
255 self.ctx_columns.clear()
256 r = self
→ 257 for func, args, kwargs in self._todo:
258 r = func(self)(*args, **kwargs)
259 return r
~/.local/lib/python3.10/site-packages/pandas/io/formats/style.py in _apply(self, func, axis, subset, **kwargs)
1665 “hidden_rows”,
1666 “hidden_columns”,
→ 1667 “ctx”,
1668 “ctx_index”,
1669 “ctx_columns”,
~/.local/lib/python3.10/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwargs)
9421 Apply a function along an axis of the DataFrame.
9422
→ 9423 Objects passed to the function are Series objects whose index is
9424 either the DataFrame’s index (axis=0
) or the DataFrame’s columns
9425 (axis=1
). By default (result_type=None
), the final return type
~/.local/lib/python3.10/site-packages/pandas/core/apply.py in apply(self)
676 # “Union[Series, DataFrame, GroupBy[Any], SeriesGroupBy,
677 # DataFrameGroupBy, BaseWindow, Resampler]”; expected “Union[DataFrame,
→ 678 # Series]”
679 return self.obj.index # type:ignore[arg-type]
680
~/.local/lib/python3.10/site-packages/pandas/core/apply.py in apply_standard(self)
796 “”"
797 we have an empty result; at least 1 axis is 0
→ 798
799 we will try to apply the function to an empty
800 series in order to see if this is a reduction function
~/.local/lib/python3.10/site-packages/pandas/core/apply.py in apply_series_generator(self)
812 from pandas import Series
813
→ 814 if not should_reduce:
815 try:
816 if self.axis == 0:
~/.local/lib/python3.10/site-packages/pandas/core/apply.py in f(x)
131
132 self.result_type = result_type
→ 133
134 # curry if needed
135 if (
~/.local/lib/python3.10/site-packages/pandas/io/formats/style.py in _background_gradient(data, cmap, low, high, text_color_threshold, vmin, vmax, gmap, text_only)
3627 -------
3628 self : Styler
→ 3629
3630 See Also
3631 --------
AttributeError: ‘ColormapRegistry’ object has no attribute ‘get_cmap’