简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM