我想用python编写一个函数,返回csv中一列和一个输入字符串的第一个精确匹配。你知道吗
这是输入csv。药品列表是标题。我想检查输入文件(string)中的6个字符串,代码应该返回输入字符串中药品列表中第一个完全匹配的名称。你知道吗
要检查的关键字:
Drug product(s) list
solution for injection
suspension for injection
film-coated tablet
concentrate for solution for infusion
cream
modified-release tablet
应检查关键字的输入字符串:
This supplemental application, submitted as a “Changes Being Effected” supplement, proposes
the revisions in the incubation scheme for routine environmental monitoring of swab samples of film-coated tablet Alpuzim
with the incubation scheme for contact plates. Also submission for Alpuzim cream is pending.
该函数只应返回文件中的第一个匹配项,即薄膜涂布片。一旦找到第一个匹配项,输入字符串中的循环就应该中断
这就是我一直尝试的:
import csv
def first_Occurrence(string):
with open('C:\\Users\\Lenovo\\.spyder-py3\\unique_final_drug_products.csv', newline='', encoding ='utf-8') as myFile:
reader = csv.reader(myFile)
for row in reader:
product = row[0].lower()
for i in range(len(string)):
i = i.lower()
if(string[i] == product):
return i
return ('string not found')
a = first_Occurrence('we have a solution cream for back pain')
print(a)
我不是要解决你的问题,而是the logic to what you are looking for is here
相关问题 更多 >
编程相关推荐