使用 dataframe.style 时从 .render() 切换到 .to_html() ,现在收到 TypeError: Cannot pickle 'module'目的

发布于 2025-01-16 22:53:38 字数 3647 浏览 1 评论 0原文

创建数据框并设置其样式后,我最初会使用 .render() 将其转换为 html 字符串。但是,将其切换到 .to_html() 后,我收到类型错误。

在对我的数据框进行样式设计后,我将使用 .render() 将其转换为 html 字符串。但是,我收到一条警告消息:

FutureWarning: this method is deprecated in favour of `Styler.to_html()`
  return df_styled_without_date.render()

所以我将其切换为 .to_html() ,现在收到此错误:

File "C:\Python39\lib\site-packages\pandas\io\formats\style.py", line 1155, in to_html
    obj = self._copy(deepcopy=True)  # manipulate table_styles on obj, not self
  File "C:\Python39\lib\site-packages\pandas\io\formats\style.py", line 1388, in _copy
    setattr(styler, attr, copy.deepcopy(val) if deepcopy else val)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 237, in _deepcopy_method
    return type(x)(x.__func__, deepcopy(x.__self__, memo))
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'module' object

任何人都可以帮忙吗?我被困住了。

After creating a dataframe and styling it, I would originally use .render() to turn it into an html string. However, after switching it to .to_html() I am getting a type error.

After styling my dataframe I would turn it into an html string using .render(). However, I got a warning message:

FutureWarning: this method is deprecated in favour of `Styler.to_html()`
  return df_styled_without_date.render()

So I switched it to .to_html() and am now getting this error:

File "C:\Python39\lib\site-packages\pandas\io\formats\style.py", line 1155, in to_html
    obj = self._copy(deepcopy=True)  # manipulate table_styles on obj, not self
  File "C:\Python39\lib\site-packages\pandas\io\formats\style.py", line 1388, in _copy
    setattr(styler, attr, copy.deepcopy(val) if deepcopy else val)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 237, in _deepcopy_method
    return type(x)(x.__func__, deepcopy(x.__self__, memo))
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python39\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'module' object

Can anyone help? I'm stuck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文