array = df.data
names = array[:,2] # slice out the names
places = array[:,1] #slice out the places
places = [list(set(places)).index(place) for place in places] #convert the places to ints
pairs = zip(names,places) #combine the lists
dict = {}
for name in set(names): #step through each name
dict[name] = [x[1] for x in pairs where x[0] == name]
此代码将为您提供一个列表,作为字典中每个名称的条目:
不是最漂亮的代码,但它应该工作。你知道吗
相关问题 更多 >
编程相关推荐