Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to shape a array for use with scipy, sklearn etc.. I have a csv file I am importing using pandas like so -

df = pd.read_csv('data.csv')

which gives me this data -

>>print df  

Model | Trim | Cost
6     | 102  | 1200
8     | 105  | 1500
15    | 110  | 3000

I would like to shape it to an array like so

array = []
array.append(df)
>>print array

[[6,102,1200],[8,105,1500],[15,110,3000]...]

I have tried append, extend, shape, reshape and still cannot seem to get it right.. What is the correct way to accomplish this?

share|improve this question
4  
Possible duplicate of Pandas DataFrame to list – m0nhawk 14 hours ago
    
Do you want a Python list from it or a Numpy array? – Nick T 14 hours ago
2  
^ yeah you're looking for df.values.tolist() – rbierman 14 hours ago
    
Bam thanks! Seems so simple in heinz sight.. dont know how I didnt see that in my search efforts.. If you post as an answer I will accept, Thanks! – Ryan D 14 hours ago
    
@m0nhawk should get accepted answer, I just followed their link – rbierman 14 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.