0

I have a list with the following format:

data = [
    ['string1', [a, b, c]],
    ['string2', [d, e, f]],
    ['string3', [g, h, i]],
    ['string4', [j, k, l]],
]

and I would like to transform it into a data frame like so, with the strings as column names and the lists as column content:

string1     string2     string3     string4
a           d           g           j
b           e           h           k
c           f           i           l

How can I achieve that?

1 Answer 1

2

Convert values to dictionary and then to DataFrame constructor:

df = pd.DataFrame(dict(data))
print (df)
  string1 string2 string3 string4
0       a       d       g       j
1       b       e       h       k
2       c       f       i       l
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.