【发布时间】:2020-09-18 07:40:20
【问题描述】:
这是我为我的项目所做的代码,它从 csv 文件中获取值。我收到一个错误,将 csv 文件中的数据 u= 作为字符串而不是整数。如何将其转换为整数值或浮点值?
import pandas as pd
proper = []
with open("C:\\Users\\krupa\\Downloads\\proper.csv","r") as f:
for line in f:
tokens = line.split(',')
order_id =tokens[0]
country = tokens[1]
proper.append([order_id,country])
#print(proper)
proper = {}
with open("C:\\Users\\krupa\\Downloads\\proper.csv","r") as f:
for line in f:
tokens = line.split(',')
order_id =tokens[0]
country = tokens[1]
proper[order_id] = country
print(proper)
def get_hash(key):
hash = 0
for i in range(key):
hash += 1
return hash % 100000
get_hash('8469376')
这是我得到的错误
TypeError: 'str' object cannot be interpreted as an integer
【问题讨论】:
-
发布完整的回溯,以便我们查看导致错误的行?
-
必须是
get_hash(8469376)而不是get_hash('8469376')
标签: python pandas list csv hash