我有两个不同行的数据帧,dF1=(1098x2列)和 df2=(1331 x2)例如:
df1型
lat-2 long-2
R1 10.612811 46.265142
R2 10.604078 45.896510
R3 10.610205 45.727291
R4 10.606051 45.772968
R5 10.596646 46.517013
df2型
lat-1 long-1
G1 10.604065 45.896533
G2 10.612811 46.265142
G3 10.606051 45.772968
G4 10.610205 45.727291
G5 10.606747 44.772287
G6 10.619976 45.847164
G7 10.607682 45.477258
G8 10.784809 44.769609
在Get Nearest Point from each other in pandas dataframe的帮助下 我计算了df1的每一行和df2的所有行之间的欧几里德距离,因此新的df有(1089x1331)。 新建\u df
G1 G2 G3 G4 G5 G6 G7 G8
R1 0.368713 0.000000 0.492220 0.537857 1.492867 0.418039 0.787901 1.505391
R2 0.000026 0.368735 0.123558 0.169330 1.124226 0.051844 0.419267 1.141302
R3 0.169353 0.537857 0.045865 0.000000 0.955010 0.120271 0.250046 0.973469
R4 0.123581 0.492220 0.000000 0.045865 1.000681 0.075491 0.295714 1.019158
R5 0.620524 0.252389 0.744104 0.789838 1.744755 0.670255 1.039814 1.757506
我想要这样的结果:
close
R1 [G2,G1,G6,G3,G5,G4,G7,G8]
R2 [G1, G6, ,,......]
R3 [G4,...]
R4 [G3,....]
R5 [G2,G5,...]
R6 [G2,G3,...]
R7 [G4,...]
换言之,我想为new_df的每一行按升序对列的值进行排序,最后返回我想要的结果。你知道吗
我不能使用Get Nearest Point from each other in pandas dataframe的代码 我试着这样写:
def Closest(df):
d=defaultdict(list)
for x in (df.index):
y=df.loc[str(x)].copy()
M=y.tolist()
Q=M.sort_val(ascending=True)
p=Q.index
d[x].appand(p)
return (d)
我的想法是:
h=new_df.loc["R1"].copy()
h:
G1 0.368713
G2 0.000000
G3 0.492220
G4 0.537857
G5 1.492867
G6 0.418039
G7 0.787901
G8 1.505391
Name: R3, dtype: float64
k=h.sort_values(ascending=True)
k.index
d={}
d['R']=k.index
所以我想创建一个字典,其中包含索引R作为键和有序G的列表作为键值。最后,我可以用这本字典做一个数据帧。 但是当我写这个函数时,它正在发送(“'float'对象没有属性'sort\u val','occurred at index G1')或者'float'对象不是iterable。你知道吗
我是一个新的程序员(初学者)
如何纠正我的功能以达到我的目标或目标 如果我的想法是完全错误的,我怎么能有我的结果?你知道吗
您可以为df应用
rank
,然后按秩的顺序对列名排序,并创建一个新的Series
相关问题 更多 >
编程相关推荐