0
list1 = [ 1,2] 
list2 = [2,3,4]

main = pd.DataFrame( columns = ['a','b'])
main = main.append(pd.DataFrame(list1, columns=['a']), ignore_index= True)
main = main.append(pd.DataFrame(list2, columns=['b']), ignore_index= True)

Output :
a   b
1   NA
2   NA
NA  2
NA  3
NA  4

I want to expect the output of both lists in the same rows of this different list in particular columns.

1 Answers1

0

Your solution with append values of list later is possible if use concat with axis=1:

main = pd.DataFrame()
main = pd.concat([main, pd.DataFrame(list1, columns=['a'])], axis=1)
main = pd.concat([main, pd.DataFrame(list2, columns=['b'])], axis=1)
print (main)
     a  b
0  1.0  2
1  2.0  3
2  NaN  4

If possible create DataFrame first with Series by lists:

main = pd.DataFrame({'a':pd.Series(list1), 'b':pd.Series(list2)})
print (main)
     a  b
0  1.0  2
1  2.0  3
2  NaN  4
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252