我正在使用python,我想浏览一个数据集并突出显示最常用的位置。在
这是我的数据集(但有300000多条记录):Longitude Latitude
14.28586 48.3069
14.28577 48.30687
14.28555 48.30678
14.28541 48.30673
首先,我添加了一个密度列:
^{pr2}$
这是我用来增加每个记录的密度值的代码:for index in range(0,len(df)):
for index2 in range(index + 1, len(df)):
if df['Longitude'].loc[index] == df['Longitude'].loc[index2] and df['Latitude'].loc[index] == df['Latitude'].loc[index2]:
df['Density'].loc[index] += 1
df['Density'].loc[index2] += 1
print("match")
print(str(index) + "/" + str(len(df)))
上面的代码只是在dataframe中迭代,将第一条记录与数据集中的所有其他记录进行比较(内部循环),当找到匹配项时,它们的密度值都将递增。在
我想找到匹配的经纬度,并增加它们的密度值。在
代码显然非常慢,我相信Python会有一种很酷的技术来做这样的事情,有什么想法吗?在