How can I convert columns of a pandas DataFrame into a list of lists?
To change Dataframe into list use tolist() function to convert Let use say i have Dataframe df
to change into list you can simply use tolist() function
df.values.tolist()
You can also change a particular column in to list by using
df['column name'].values.tolist()
It looks like a transposed matrix:
df.values.T.tolist()
[list(l) for l in zip(*df.values)]
[[0, 0, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 1],
[0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1]]