简体   繁体   English

ValueError: int() 以 10 为底的无效文字:'81?36N'

[英]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')

Image: Line 57图片:57 号线

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.

相关问题 ValueError:int()以10为底的无效文字:&#39;\\ n&#39; - ValueError: invalid literal for int() with base 10: '\n' ValueError:int()以10为底的无效文字:b&#39;1 \\ n5 \\ n&#39; - ValueError: invalid literal for int() with base 10: b'1\n5\n' ValueError:以10为底的int()的无效文字:&#39;2 \\ n3&#39; - ValueError: invalid literal for int() with base 10: '2\n3' 显示 ValueError: 以 10 为基数的 int() 的无效文字:&#39;\\n&#39; - Showing ValueError: invalid literal for int() with base 10: '\n' ValueError: 基数为 10 的 int() 的文字无效:&#39;40 1 3 4 20\\n&#39; - ValueError: invalid literal for int() with base 10: '40 1 3 4 20\n' ValueError:以 10 为底的 int() 的无效文字:'20.00\n' - ValueError: invalid literal for int() with base 10: '20.00\n' ValueError:int() 的无效文字,基数为 10:&#39;59574966\\n9&#39; - ValueError: invalid literal for int() with base 10: '59574966\n9' 我收到此错误: ValueError: invalid literal for int() with base 10: '\n' - I get this error: ValueError: invalid literal for int() with base 10: '\n' ValueError:int() 的无效文字,基数为 10:&#39;done&#39; - ValueError: invalid literal for int() with base 10: 'done' Django:ValueError:以10为底的int()的无效文字 - Django:ValueError: invalid literal for int() with base 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM