[英]ValueError: invalid literal for int() with base 10 : '81?36N'
Traceback (most recent call last):
File "/Users/HectorVelasquez/PycharmProjects/Project 1/Project 1 python.py", line 57, in <module>
df['log'] = df['Latitude'].apply(lambda x: convert_rad(x))
File "/Users/HectorVelasquez/PycharmProjects/Project 1/venv/lib/python3.7/site-packages/pandas/core/series.py", line 4045, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas/_libs/lib.pyx", line 2228, in pandas._libs.lib.map_infer
File "/Users/HectorVelasquez/PycharmProjects/Project 1/Project 1 python.py", line 57, in <lambda>
df['log'] = df['Latitude'].apply(lambda x: convert_rad(x))
File "/Users/HectorVelasquez/PycharmProjects/Project 1/Project 1 python.py", line 7, in convert_rad
degree = int(temp[0]) + int(temp[1][:-1])/60
ValueError: invalid literal for int() with base 10: '81?36N'
text file I don't know how to fix the error.文本文件我不知道如何修复错误。
Latitude Longitude City Province/State Country纬度 经度 城市 省/州 国家
81?36N 16?40W Nord Greenland Denmark 81?36N 16?40W Nord Greenland Denmark
79?59N 85?56W Eureka Nunavut Canada 79?59N 85?56W 尤里卡努纳武特加拿大
78?55N 11?56E Ny-?lesund Svalbard Norway 78?55N 11?56E Ny-?lesund Svalbard 挪威
78?13N 15?39E Longyearbyen Svalbard Norway 78?13N 15?39E Longyearbyen Svalbard 挪威
conversion function转换 function
def convert_rad(lon):
temp = lon.split('°')
degree = int(temp[0]) + int(temp[1][:-1])/60
direction = temp[1][-1]
if direction=='N' or direction=='E':
sign = 1
elif direction=='S' or direction=='W':
sign = -1
return degree*sign*np.pi/180
Latitude_66N = convert_rad('66°0N')
Latitude_35N_66N = convert_rad('35°0N')
Latitude_35S_35N = convert_rad('35°0S')
Latitude_35S_66S = convert_rad('66°0N')
Latitude_66S = convert_rad('66°0N')
lon = convert_rad('37°22N')
lat = convert_rad('120°42W')
Try debugging your problem a little and ask a minimal version of it, with enough code to reproduce it elsewhere (eg file and functions).尝试稍微调试一下您的问题并询问它的最小版本,并使用足够的代码在其他地方重现它(例如文件和函数)。 If you look at your traceback you can see the error is on the first line.
如果您查看回溯,您会看到错误在第一行。 In general text is much much more useful than screenshots of text.
一般来说,文本比文本截图有用得多。 That being said
话虽如此
df = pd.read_csv('cities.txt', sep='\t', encoding='latin_1')
df['log'] = df['Latitude'].apply(lambda x: convert_rad(x))
Ignoring the backwards 'log'
and 'Latitude'
, I can see from your traceback your custom function convert_rad
has忽略向后
'log'
和'Latitude'
,我可以从您的回溯中看到您的自定义 function convert_rad
有
degree = int(temp[0]) + int(temp[1][:-1])/60
somewhere in it.在它的某个地方。 Try taking a look at your csv file for the string
81?36N
, or just using the first few lines of the file.尝试查看字符串
81?36N
的 csv 文件,或者仅使用文件的前几行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.