【发布时间】:2019-10-24 13:40:33
【问题描述】:
我有一些英国监测站点的臭氧水平数据,并给出了每个站点的纬度和经度,例如:
df = pd.DataFrame([[33. , 52.411563, -1.560228],
[45. , 52.437165, -1.829999],
[31. , 52.47609 , -1.875024],
[53. , 50.5976 , -3.71651 ],
[39. , 50.37167 , -4.142361],
[41. , 50.725083, -3.532465],
[69. , 51.05625 , -2.68345 ],
[38. , 51.462839, -2.584482],
[56. , 50.73957 , -1.826744]],columns = ['values','lat','lon'])
我想将这些点绘制为网格正方形,使用位于同一网格框中的点的平均值为它们着色,使用官方网格 0.25x0.3125km,其纬度和经度由下式给出:
grid = {'lon':np.linspace(-15.00,40,177),
'lat':np.linspace(32.75,61.25,115)} #should define the grid squares for the map
我试图检查我的纬度和经度列,将每个值重新分配给它最近的经纬度对。这似乎可行。
for i, [time, val, lat, lon] in DEFRAO3.iterrows():
pos_lat = bisect_left(nested_grid['lat'],lat)
new_lat = nested_grid['lat'][pos_lat]
pos_lon = bisect_left(nested_grid['lon'],lon)
new_lon = nested_grid['lon'][pos_lat]
DEFRAO3.set_value(i, 'latitude', new_lat)
DEFRAO3.set_value(i, 'longitude', new_lon)
DEFRAO3
给予:
然后,对具有相同 (lat,lon) 的位置进行平均:
newDEFRA = DEFRAO3.groupby(['latitude','longitude'], as_index=False).mean()
但是当我绘制它时,我所有的点都在同一条对角线上。
【问题讨论】: