<class 'pandas.core.frame.DataFrame'>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-18d68697e7bd> in <module>
1 a = df.quantile([0.25, 0.50, 0.75]);
2 print(type(a))
----> 3 a = a.tolist()
4 print(type(a))
~\.conda\envs\pybase\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
5137 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5138 return self[name]
-> 5139 return object.__getattribute__(self, name)
5140
5141 def __setattr__(self, name: str, value) -> None:
AttributeError: 'DataFrame' object has no attribute 'tolist'
Oftentimes we want to convert a dataframe or a column of a dataframe to a list. the pandas function tolist (link to documentation) is used. But then you get the error above.
The function syntax is pandas.Series.tolist which means that you need to specify the pandas series on which to use this as seen in the code snippet screenshot below
Note: If you have multiple columns then this may cause problems with datatypes; better to use list comprehension as explained in this stackoverflow post.
Comments
Post a Comment