代码之家  ›  专栏  ›  技术社区  ›  Rekha Chittibabu

如何使用python检查列表中的字符串是否存在于CSV文件的特定列中?

  •  0
  • Rekha Chittibabu  · 技术社区  · 7 年前

    我尝试了以下方法 此处target\u 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
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   PyMaster    7 年前

    我修改了代码,从PLM中的列中找到target\u条件列表的值。csv文件。

    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)])
    

    我希望这对你有帮助。