我正在尝试从大型csv文件中仅导出具有特定条件的某些行...在第13行中查找具有特定评级的行时,我一直收到错误。评级为整数和半小数(示例如下) )。
评级
5
4.5
3
1
4
4
3.5
这是我的代码......
import csv
citys = [
raw_input ("Enter City Name:"),
]
states = [
raw_input ("Enter State Name:"),
]
categorys = [
'Auto Repair',
]
ratings = [
'5',
]
listname = raw_input ("Enter List Name:")
listname_accept = (listname) + '.csv'
with open('master.csv', 'r') as master, open((listname_accept), 'w') as matched:
reader = csv.reader(master)
writer = csv.writer(matched)
writer.writerow(next(reader))
for row in reader:
if row[5] in citys and row[6] in states and row[2] in categorys and row[13] in ratings:
writer.writerow(row)
当我运行它时,它只打印标题行。我知道第13行是正确的,肯定有匹配的行。
以下是csv ...
的示例url,name,category,display_address,street,city,state_code,postal_code,neighborhood,cross_street,phone,website,review,rating
www.url.com,Business 1,Auto Repair,"123 Any St., City, State, 12345",123 Any St,City,State,12345,Long Island City,None,999-999-9999,www.website.com,18,5
www.url.com,Business 2,"Auto Repair , Body Shops , Towing","123 Any St., City, State, 12345",123 Any St,City,State,12345,Long Island City,None,999-999-9999,www.website.com,67,4.5
www.url.com,Business 3,Auto Repair,"123 Any St., City, State, 12345",123 Any St,City,State,12345,Long Island City,None,999-999-9999,www.website.com,14,5
www.url.com,Business 3,"Body Shops , Auto Repair","123 Any St., City, State, 12345",123 Any St,City,State,12345,Long Island City,None,999-999-9999,www.website.com,14,1.5
无视其他标准,理想情况下,它应该返回"业务1"和"商业3"。