lsr729
lsr729

Reputation: 832

How to add or concatenate two or more lists row wise to create dataframe in Python

I want to add two or more lists/ pandas series row wise to make a dataframe, how do I do that? for example, Inputs=

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

(Or pandas series can be there)

Desired output =

1 2 3 4
9 8 7 6

Upvotes: 1

Views: 861

Answers (1)

jezrael
jezrael

Reputation: 862611

Create list of lists/Series and pass to DataFrame constructor:

L = [a,b]
df = pd.DataFrame(L)
print (df)
   0  1  2  3
0  1  2  3  4
1  9  8  7  6

Upvotes: 2

Related Questions