ValueError: invalid literal for int() with base 10: '1127437398.85751'
来源:互联网 发布:艾瑞数据分析 编辑:程序博客网 时间:2024/06/06 06:55
# load the needed data to the list
filename = 'population_data.json'
with open(filename) as f:
pop_data = json.load(f)
#print(pop_data)
for pop_dict in pop_data:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = int(pop_dict['Value'])
print(country_name + ": " + str(population))
Arab World: 357868000
Caribbean small states: 6880000
East Asia & Pacific (all income levels): 2201536674
East Asia & Pacific (developing only): 1961558757
Euro area: 331766000
Europe & Central Asia (all income levels): 890424544
Europe & Central Asia (developing only): 405204000
European Union: 502125000
Heavily indebted poor countries (HIPC): 635663000
Traceback (most recent call last):
File "world_population.py", line 13, in <module>
population = int(pop_dict['Value'])
ValueError: invalid literal for int() with base 10: '1127437398.85751'
# int function can not directly deal with strings like 34423.22323, we should transfer the string into a float first,
# then problem solved!!!
import json
# load the needed data to the list
filename = 'population_data.json'
with open(filename) as f:
pop_data = json.load(f)
#print(pop_data)
for pop_dict in pop_data:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = int(float(pop_dict['Value']))
print(country_name + ": " + str(population))
- ValueError: invalid literal for int() with base 10: '1127437398.85751'
- ValueError: invalid literal for int() with base 10
- ValueError: invalid literal for int() with base 10
- ValueError: invalid literal for int() with base 10: '2.0'
- Python debug ValueError: invalid literal for int() with base 10:
- ValueError: invalid literal for int() with base 10: ''
- ValueError: invalid literal for int() with base 10: 'largeDoses'
- ValueError: invalid literal for int() with base 10: ' ' 文本转化为向量错误解决
- 用scrapy框架时,出现问题:ValueError: invalid literal for int() with base 10: 'dev0'
- repo init 报:ValueError: invalid literal for int() with base 10: '8 (Apple Git-58)'
- machine learning in action出现ValueError: invalid literal for int() with base 10: 'largeDoses'
- ValueError: invalid literal for int() with base 10: '7.8000000e+02'
- 完美解决ValueError: invalid literal for int() with base 10 错误问题
- Python debug —— invalid literal for int() with base 10
- 《机器学习实战》 2.1 小节 kNN 算法中 invalid literal for int() with base 10:‘largeDoses
- moviepy ValueError: Invalid value for quantizer: 'wu'
- ValueError: invalid \x escape
- [invalid literal/length code]
- 移动端——JS
- llibsvm-svdd 用法示例
- windows 查看DLL导出函数的方法
- 1070: 上车人数
- CSS3新增选择器
- ValueError: invalid literal for int() with base 10: '1127437398.85751'
- 0/1背包问题-----回溯法求解
- bzoj 2216: [Poi2011]Lightning Conductor 决策单调性+cdq分治
- 河南省第十届ACM大学生程序设计竞赛总结
- 逆向工程核心原理学习笔记(二十三):栈帧10:设置返回值,删除栈帧&main()函数终止
- 弹力球事件
- VTK实现简单科学可视化
- Linux之file_struct&fd(file descriptor)
- 文件IO编程五