【发布时间】:2018-04-20 02:37:53
【问题描述】:
我有一个这样的数据框:
long lat Place -6.779 61.9 奥胡斯 -6.790 62.0 奥胡斯 54.377 24.4 扎比 38.834 9.0 亚的斯 35.698 9.2 亚的斯Is it possible to transform the dataframe into a format like below? Office long + lat Aarhus [[-6.779,61.9], [-6.790,62.0]] Dhabi [[54.377]] Addis [[38.834,9.0], [35.698,9.2]]我尝试了不同的方法,但仍然无法解决这个问题。这是 我试图为每个不同的位置值获取一个列表:
df2["index"] = df2.index df2["long"]=df2.groupby('index')['long'].apply(list) list 1= [] for values in ofce_list: if df['Office'].any() == values: list1.append(df.loc[df['Office'] == values, 'long']) But this returned a series in a list instead which is not desired. Please help. Thank you so much.
【问题讨论】:
标签: python list pandas group-by