Back
It's easy to turn a list of lists into a pandas dataframe:
import pandas as pddf = pd.DataFrame([[1,2,3],[3,4,5]])
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]]
lol = df.what_to_do_now?
print lol
# [[1,2,3],[3,4,5]]
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]]
>>> 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