Reputation: 77
I have some lists with different length and I am going to store them in one dataframe.
list1=[('G06F', 'H04L'),('H04N','G06F')]
list2=[('E06F', 'T08L'),('H05M', 'H03D'),('A05V', 'N03D')]
list3=[('M04F', 'A01B')]
I have been trying to have these lists in a dataframe coming with one row for each list.
I used mylist.append()
, but it put the new list in one element after the former one
list2.append(simple_list1)
>>out:
[('E06F', 'T08L'), ('H05M', 'H03D'), ('A05V', 'N03D'), [('G06F', 'H04L'), ('H04N', 'G06F')]]
Upvotes: 0
Views: 56
Reputation: 2870
You can do it this way.
list1=[('G06F', 'H04L'),('H04N','G06F')]
list2=[('E06F', 'T08L'),('H05M', 'H03D'),('A05V', 'N03D')]
list3=[('M04F', 'A01B')]
list_combied = pd.DataFrame([[list1, list2, list3]]).T
list_combied
0 [(G06F, H04L), (H04N, G06F)]
1 [(E06F, T08L), (H05M, H03D), (A05V, N03D)]
2 [(M04F, A01B)]
Upvotes: 1
Reputation: 1779
use +
list1=[('G06F', 'H04L'),('H04N','G06F')]
list2=[('E06F', 'T08L'),('H05M', 'H03D'),('A05V', 'N03D')]
list3=[('M04F', 'A01B')]
lists = list1 + list2 + list3
print (lists)
The result is
[('G06F', 'H04L'), ('H04N', 'G06F'), ('E06F', 'T08L'), ('H05M', 'H03D'), ('A05V', 'N03D'), ('M04F', 'A01B')]
Upvotes: 0