Pandas DataFrame to List of Lists

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]]

You could access the underlying array and call its tolist method:

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

From: stackoverflow.com/q/28006793

Back to homepage or read more recommendations: