用于转换 pandas 系列中的坐标并附加为其他系列的函数 [英] Function to convert coordinates in pandas series and append as additional series
问题描述
我希望将一系列坐标存储在熊猫数据框中,并定义一个函数,该函数将遍历每个条目,对其进行转换(将BNG Easting Northing转换为Lat和Long)并将其保存到以下位置的新列中同一行. Elise Huard的功能看起来它应该这样做
I'm looking to take as series of co-ordinates stored in a pandas dataframe and define a function that will go through each entry, transform it (BNG Easting Northing to Lat and Long) and save it to a new column in same row. This function by Elise Huard looks like it should do just this
def proj_transform(df):
#bng = pyproj.Proj(init='epsg:27700')
bng = pyproj.Proj("+init=EPSG:27700")
#wgs84 = pyproj.Proj(init='epsg:4326')
wgs84 = pyproj.Proj("+init=EPSG:4326")
lats = pd.Series()
lons = pd.Series()
for idx, val in enumerate(df['Easting']):
lon, lat = pyproj.transform(bng,wgs84,df['Easting'][idx], df['Northing'][idx])
lats.set_value(idx, lat)
lons.set_value(idx, lon)
df['lat'] = lats
df['lon'] = lons
return df
但是一旦我尝试运行该功能,我就会收到以下错误消息.关于可能导致此问题的任何建议,或作为工作回合的替代方法的任何建议.
but im getting the following error once i try to run the function. Any advice on what might be causing it or an alternate approach as work round.
RuntimeError: non-convergent inverse meridional dist
使用的数据样本;
Site Reference LA Reference Start Date Easting Northing
0 380500145 NaN 20130101 105175.0 105175.0
1 380500128 NaN 20060331 104000.0 104000.0
2 380500085 NaN 20030401 105055.0 105055.0
3 380500008 NaN 19980930 108480.0 108480.0
4 380500009 NaN 19980930 105415.0 105415.0
5 380500136 SHLAA20100101 105081.0 105081.0
6 380500038 NaN 19980930 105818.0 105818.0
推荐答案
如@ptrj所述;
RuntimeError: non-convergent inverse meridional dist
在这种情况下,是由数据中的NaN值引起的.
Was, in this instance, caused by NaN values in the data.
这篇关于用于转换 pandas 系列中的坐标并附加为其他系列的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!