我最近为某人编写了一个 python 脚本,在那里我使用to_list(). 然而,这对他们不起作用,因为他们得到了:AttributeError: 'Index' object has no attribute 'to_list'使用他们的 python 解释器。
我做了一些搜索,发现tolist()似乎也有同样的事情to_list():在Pandas 文档上搜索发现两者,逐字描述相同。另一方面,Index的文档只提到了to_list().
所以我想知道两者之间是否有区别
扩展 buran 的答案(文本太多,无法放入评论中):git blame在指出的源代码上使用,可以看到它to_list()确实在 2018 年 12 月作为tolist(). 它COMMITED,以增强解决问题8826,即用,使之更加内联to_period()和to_timestamp()。
此外,更改和评论pandas/core/series.py表明原件tolist()是“半弃用的”:
# tolist is not actually deprecated, just suppressed in the __dir__
_deprecations = generic.NDFrame._deprecations | frozenset(
['asobject', 'reshape', 'get_value', 'set_value',
'from_csv', 'valid'])
'from_csv', 'valid', 'tolist'])
Run Code Online (Sandbox Code Playgroud)
有趣的是看看系统是如何工作的......