I have a problem where I need to convert a pandas dataframe into an array of list of lists.
Sample:
import pandas as pd
df = pd.DataFrame([[1,2,3],[2,2,4],[3,2,4]])
I know there is the as_matrix() function which returns below:
df.as_matrix():
# result:array([[1, 2, 3],
[2, 2, 4],
[3, 2, 4]])
However, I require something in this format
[array([[1], [2], [3]]),
array([[2], [2], [4]],
array([[3], [2], [4]])]
IE. I need a list of arrays containing list of lists where the inner most list contains a single element and the outer most list in the array represents the row of the dataframe. The effect of this is that it basically vectorizes each row of the dataframe into a vector of dimension 3.
This is useful especially when I need to do matrix / vector operations in numpy and currently the data source I have is in .csv format and I am struggling to find a way to convert a dataframe into a vector.