简体   繁体   中英

Is it possible to store some lists with different length in one dataframe?

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')]]

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')]

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)]  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM