I have a pandas data frame like this:
admit gpa gre rank 0 3.61 380 3 1 3.67 660 3 1 3.19 640 4 0 2.93 520 4
Now I want to get a list of rows in pandas like:
[[0,3.61,380,3], [1,3.67,660,3], [1,3.19,640,4], [0,2.93,520,4]]
How can I do it?
There is a built in method which would be the fastest method also, calling tolist
on the .values
np array:
df.values.tolist() [[0.0, 3.61, 380.0, 3.0], [1.0, 3.67, 660.0, 3.0], [1.0, 3.19, 640.0, 4.0], [0.0, 2.93, 520.0, 4.0]]
you can do it like this:
map(list, df.values)
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