0

I have several list:

a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
c = [7, 8, 9, 10]

I would like a dataframe with 3 columns named automatically using names of the lists

a b c
1 5 7
2 6 8
3 7 9
4 8 10

How to do this? Thank you.

0

1 Answer 1

1

You can create a Pandas DataFrame from a list using the code below:

import pandas as pd

a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
c = [7, 8, 9, 10]

df = pd.DataFrame(list(zip(a, b, c)),
                  columns =['a', 'b', 'c'])

print(df)

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to name the columns automatically as there are many lists with long names? Thanks
that 'columns' argument is the one
If you wanted to have string "names" associated with the lists, you should have built a dict in the first place, instead of separately named lists.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.