这是数据集:
uk_quar = uk_quar[['latitude','longitude']]
uk_quar.head()
latitude longitude
0 31°03'58.9"N 78°07'15.2"E
1 30°20'42.9"N 78°27'37.1"E
2 30°19'15.3"N 78°32'10.3"E
3 30°17'55.3"N 78°26'09.2"E
4 NaN NaN
5 30°23'58.8"N 77°45'20.7"E
当我尝试使用 dms2dec 转换为十进制坐标时,如下所示:
uk_quar['lat_dms']=uk_quar['latitude'].apply(dms2dec)
我得到TypeError: expected string or bytes-like object如下:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-567-2fee9b81372c> in <module>
1 #Translate the ukd haven radian coordinates into dms coordinates
----> 2 uk_quar['lat_dms']=uk_quar['latitude'].apply(dms2dec)
~/opt/anaconda3/envs/ds/lib/python3.8/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
3846 else:
3847 values = self.astype(object).values
-> 3848 mapped = lib.map_infer(values, f, convert=convert_dtype)
3849
3850 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
~/opt/anaconda3/envs/ds/lib/python3.8/site-packages/dms2dec/dms_convert.py in dms2dec(dms_str)
30 """
31
---> 32 dms_str = re.sub(r'\s', '', dms_str)
33
34 sign = -1 if re.search('[swSW]', dms_str) else 1
~/opt/anaconda3/envs/ds/lib/python3.8/re.py in sub(pattern, repl, string, count, flags)
208 a callable, it's passed the Match object and must return
209 a replacement string to be used."""
--> 210 return _compile(pattern, flags).sub(repl, string, count)
211
212 def subn(pattern, repl, string, count=0, flags=0):
TypeError: expected string or bytes-like object
列的当前数据类型以供参考。
uk_quar['latitude'].dtypes
dtype('O')
如何解决此错误并转换为十进制坐标?
不负相思意
相关分类