這是數據集:uk_quar = uk_quar[['latitude','longitude']]uk_quar.head() latitude longitude0 31°03'58.9"N 78°07'15.2"E1 30°20'42.9"N 78°27'37.1"E2 30°19'15.3"N 78°32'10.3"E3 30°17'55.3"N 78°26'09.2"E4 NaN NaN5 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'].dtypesdtype('O')如何解決此錯誤并轉換為十進制坐標?
無法使用 dms2dec 將 Pandas 數據框坐標轉換為小數
慕的地6264312
2023-03-08 16:32:13