Skip to content Skip to sidebar Skip to footer

Convert Python Dataframe To List

I have a Python dataFrame with multiple columns. LogBlk Page BayFail 0 0 [0, 1, 8, 9]

Solution 1:

pandas.Series, has a tolist method:

In [10]: import pandas as pd

In [11]: s = pd.Series([0,1,8,9], name = 'BayFail')

In [12]: s.tolist()
Out[12]: [0L, 1L, 8L, 9L]

Technical note: In my original answer I said that Series was a subclass of numpy.ndarray and inherited its tolist method. While that's true for Pandas version 0.12 or older, In the soon-to-be-released Pandas version 0.13, Series has been refactored to be a subclass of NDFrame. Series still has a tolist method, but it has no direct relationship to the numpy.ndarray method of the same name.

Post a Comment for "Convert Python Dataframe To List"