I recently wrote a python script for someone, where I converted a pandas dataframe's index into a list using to_list(). However, this does not work for them, as they get: AttributeError: 'Index' object has no attribute 'to_list' with their python interpretter.
I did some searching and found that there is also tolist() that seems to do the same as to_list(): searching on Pandas documentation finds both, with word-for-word identical description.
On the other hand, the documentation of Index mentions only to_list().
So I wonder whether there is a difference between the two
If you check the source code, you will see that right after tolist() code there is line to_list = tolist, so to_list is just alias for tolist
EDIT:  to_list() was added in ver. 0.24.0, see issue#8826
Expanding on buran's answer (too much text to fit into a comment):
Using git blameon the pointed-out source code, one can see that to_list() was indeed added in December 2018 as an alias to tolist(). It was commited as an enhancement to resolve issue 8826, i.e., to make it more inline with to_period() and to_timestamp().
Moreover, changes and comments in pandas/core/series.py show that the original tolist() is "semi-deprecated":
# 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'])
Interesting to see how the system works...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With