I am trying to get pandas DataFrame columns as a list of values.
I can access the first column using iloc :
df.ix[:,[0]].values
However, this returns an array of lists:
>>> df3.ix[:,[1]].values array([[ 0.], [ 0.], [ 0.],
How can I return a list of numbers?
I can get what I want by calling the column by name and using tolist() :
>>> df3['D-328'].tolist() [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 15.0,
However, when calling a column by index, this method is not available:
>>> df3.ix[:,[0]].tolist() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Anaconda\lib\site-packages\pandas\core\generic.py", line 2360, in __getattr__ (type(self).__name__, name)) AttributeError: 'DataFrame' object has no attribute 'tolist'
python pandas dataframe
Charon
source share