2 回答
TA贡献1836条经验 获得超3个赞
根据我的理解,我已经完成了该问题的实现。
group = df.groupby("x").groups
def neighbour(temp):
temp_final = []
final = []
for i in range(len(temp)):
t = []
for j in range(len(temp)):
if abs(temp[i] - temp[j]) <= 20:
t.append(temp[j])
else:
pass
t = sorted(t)
temp_final.append(t)
temp_final = list(set(frozenset(sublist) for sublist in final))
for i in range(len(temp_final)):
u = []
for item in temp_final[i]:
u.append(item)
final.append(u)
return final
dataframes = {}
for i in range(len(val)):
key_name = "dataframe_"+str(i)
dg = pd.DataFrame()
for item in val[i]:
index = list(group[item])
for i in range(len(index)):
dg = dg.append(df.iloc[index[i]])
dataframes[key_name] = dg
如有任何误解,请通知我。
dataframes
{'dataframe_0': Nxt w x xw y yh
5 886.0 299.0 497.0 791.0 2198.0 2261.0
2 492.0 1704.0 490.0 2196.0 2419.0 2716.0
3 886.0 302.0 492.0 794.0 2310.0 2373.0
1 492.0 1224.0 501.0 1725.0 2715.0 2847.0, 'dataframe_1': Nxt
w x xw y yh
0 501.0 1735.0 357.0 2092.0 2987.0 3129.0
7 1323.0 600.0 375.0 1092.0 1663.0 2180.0, 'dataframe_2': Nxt
w x xw y yh
4 492.0 126.0 886.0 1012.0 2309.0 2370.0
6 492.0 124.0 886.0 1010.0 2197.0 2258.0}
这是输出。
添加回答
举报