0

Have two lists list1 and list2. I'm trying to append these two lists into a final_list. Then convert it to a dataframe.

list1

list1 =[['a', 'e'], ['b', 'f'], ['c', 'g'], ['d', 'h']]

list2

list2 = [['1', '5'], ['2', '6'], ['3', '7'], ['4', '8']]

Sample Output:

Appended final_list

final_list = [['a', 'e'], ['b', 'f'], ['c', 'g'], ['d', 'h'],['1', '5'], ['2', '6'], ['3', '7'], ['4', '8']]


pd.DataFrame(final_list)


    0   1
0   a   e
1   b   f
2   c   g
3   d   h
4   1   5
5   2   6
6   3   7
7   4   8

2 Answers2

0

Im guessing the code fragment in the final block is what you want out, and you had problems getting the lists to merge into one list? If so you can just add your two lists:

list1 =[['a', 'e'], ['b', 'f'], ['c', 'g'], ['d', 'h']]
list2 =[['1', '5'], ['2', '6'], ['3', '7'], ['4', '8']]

final=list1+list2

import pandas as pd

df=pd.DataFrame(final)`
Alex S
  • 231
  • 1
  • 10
0

You basically want to create an empty final list and then use extend to add the elements of list_1 and list_2

l3 = []
l3.extend(list1)
l3.extend(list2)
nickyfot
  • 1,932
  • 17
  • 25