QQ1821
QQ1821

Reputation: 143

How to put list from a list of list in a dataframe

I am wondering how can I generate a dataframe from my list of list

A=[['a','b','c'],['c','d','e'],['f','g','h']]

such that I obtain a dataframe with only 1 column and 3 rows containing the differents list ['a','b','c'],['c','d','e'] and ['f','g','h'] respectively

Upvotes: 0

Views: 29

Answers (2)

Asish M.
Asish M.

Reputation: 2647

Try using:

In [40]: pd.Series(A, name='col').to_frame()
Out[40]:
         col
0  [a, b, c]
1  [c, d, e]
2  [f, g, h]

Upvotes: 3

Sparrow0hawk
Sparrow0hawk

Reputation: 577

You could do this by casting A as a value within a dict.

>>> A=[['a','b','c'],['c','d','e'],['f','g','h']]
>>> import pandas as pd
>>> pd.DataFrame({'col':A})
         col
0  [a, b, c]
1  [c, d, e]
2  [f, g, h]

Upvotes: 2

Related Questions