[英]How to check if a string in a list is present in a particular column in a CSV file using python?
I tried the following here target_conditions is the list which is to be compared with a column in PLM 我在这里尝试了以下target_conditions是要与PLM中的列进行比较的列表
csv file
with open('PLM.csv', 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
for str in target_conditions:
str=str.split(',')
if str in row[3]:
print ("is in file") #but i need the patient name to be displayed
I have modified the code to find the value of target_conditions list from the column in PLM.csv file. 我修改了代码以从PLM.csv文件中的列中找到target_conditions列表的值。
with open('PLM.csv', 'rt') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
for str in target_conditions:
if str in row:
print(row[row.index(str)])
I hope this will help you. 我希望这能帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.