Categories
Python Answers

How to convert Python Pandas DataFrame to list of lists?

Spread the love

Sometimes, we want to convert Python Pandas DataFrame to list of lists.

In this article, we’ll look at how to convert Python Pandas DataFrame to list of lists.

How to convert Python Pandas DataFrame to list of lists?

To convert Python Pandas DataFrame to list of lists, we can use the tolist method.

For instance, we write

df = pd.DataFrame([[1,2,3],[3,4,5]])
lol = df.values.tolist()

to call df.values.tolist to return a nested list with the values in the df data frame.

Conclusion

To convert Python Pandas DataFrame to list of lists, we can use the tolist method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *