我是Python及其泡菜格式的新手。
所以当我写到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
任何人都知道为什么会这样,以及如何解决这个问题?
感谢。
答案 0 :(得分:2)
我有同样的问题。就我而言,这是由于向数据帧中添加了bs4.element.NavigableString元素引起的。将其转换为字符串可以解决问题!
注释“在行返回(unicode(self),):变量self的值是什么?”让我解决问题,谢谢!我在错误消息中注意到了bs4 \ element.py。我意识到我(不小心)也在我的数据框中添加了bs4项目。我错误地认为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