简体   繁体   English

大熊猫腌渍错误 - 超出最大递归深度

[英]Pandas to pickle error - maximum recursion depth exceeded

I'm new to Python and its pickle format. 我是Python及其pickle格式的新手。

So I came across an error message when I wrote to_pickle. 所以当我写到to_pickle时,我遇到了一条错误消息。

>>> import pandas as pd
>>> old = pd.read_pickle('vol.pkl')
>>> old = old.append(updates)
>>> pd.to_pickle(old,'vol.pkl')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "\\\python-site-packages\win64_vc11\Lib\site-packages\pandas-0.13.0-py2.7-win-amd64.egg\pandas\io\pickle.py", line 15, in to_pickle
    pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL)
  File "\\\python-site-packages\win64_vc11\Lib\site-packages\bs4\element.py", line 664, in __getnewargs__
    return (unicode(self),)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Anyone knows why this happens and how to solve this? 谁知道为什么会这样,以及如何解决这个问题?

Thanks. 谢谢。

I had the same problem. 我有同样的问题。 In my case it was caused by adding a bs4.element.NavigableString element to the dataframe. 在我的情况下,它是由向数据帧添加bs4.element.NavigableString元素引起的。 Converting that to a string solved the issue! 将其转换为字符串解决了问题!

The comment "In the line return (unicode(self),): what is the value of the variable self?" 注释“在行返回(unicode(self),):变量self的值是多少?” put me to the solution, thanks! 把我解决了,谢谢! I noticed the bs4\\element.py in the error message. 我注意到错误消息中的bs4 \\ element.py。 I realised that I was (accidently) also adding bs4 items to my dataframe. 我意识到我(意外地)也在我的数据框中添加了bs4项。 I incorrectly assumed that soup.title.string returned a string but it returned a type bs4.element.NavigableString. 我错误地认为soup.title.string返回了一个字符串,但它返回了一个类型bs4.element.NavigableString。

    # the issue: type(title) = bs4.element.NavigableString

    ~\Anaconda3\lib\site-packages\bs4\element.py in __getnewargs__(self)
    784 
    785     def __getnewargs__(self):
--> 786         return (str(self),)
    787 
    788     def __getattr__(self, attr):

RecursionError: maximum recursion depth exceeded while getting the str of an object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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