2016-06-14 10 views

Antwort

2

versuchen Sie dies:

In [301]: df.groupby('Name')['Attribute'].apply(lambda x: tuple(x.tolist())).reset_index() 
Out[301]: 
    Name Attribute 
0 A (b1, b5) 
1 B (b2, b4) 
2 C (b3, b7) 
2

Try this, No Lambda:

df.groupby('Name')['Attribute'].apply(tuple).reset_index() 
0

Aus diesem Grund Wörterbücher wurden aktualisiert:

myfile = open('yourfile.txt','r').readlines() 
mydict = {} 
for line in myfile[1:]: 
    data = line.split() 
    if data[0] in mydict: 
     mydict[data[0]].append(data[1]) 
    else: 
     mydict[data[0]] = [data[1]] 
Verwandte Themen