Alana
Alana

Reputation: 89

Pandas Dataframe

For example:

d=['a','b','c','d']
e=['1','2','3','4']
f=['e','f','g','h']

I am wondering how to output the following dataframe:

a b c d
1 2 3 4
e f g h

Thanks

Upvotes: 0

Views: 45

Answers (2)

Gaurav Neema
Gaurav Neema

Reputation: 166

Try this:

data=[]
data.append(d)
data.append(e)
data.append(f)
data=pd.DataFrame(data)
print (data)

Upvotes: 0

Sven Harris
Sven Harris

Reputation: 2939

You can simply pass in the lists as rows into the DataFrame constructor

import pandas as pd
pd.DataFrame(data=[d,e,f])

Upvotes: 3

Related Questions