使用 dataframe.style 时从 .render() 切换到 .to_html() ,现在收到 TypeError: Cannot pickle 'module'目的
创建数据框并设置其样式后,我最初会使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论