Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

It's easy to turn a list of lists into a pandas dataframe:

import pandas as pd

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

But how do I turn df back into a list of lists?

lol = df.what_to_do_now?

print lol

# [[1,2,3],[3,4,5]]

1 Answer

0 votes
by (41.4k points)

1. Access the underlying array.

2.Then, call its tolist method.

>>> df = pd.DataFrame([[1,2,3],[3,4,5]])

>>> lol = df.values.tolist()

>>> lol

[[1L, 2L, 3L], [3L, 4L, 5L]]

If you are interested to learn Pandas visit this Python Pandas Tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...