在excel中匹配特定字符串并使用python打印这些行

在excel中匹配特定字符串并使用python打印这些行,python,excel,csv,Python,Excel,Csv,我正在尝试打印excel中4列的值。我需要匹配第4列中的一个特定字符串,然后只打印包含该字符串的行。(例如:如果第二行的第四列包含“Sweet”,我将打印整行) excel示例: name; number; fruit; comment test1 ;1 ; apple ; healthy test2; 2; banana ;sweet and healthy 这里应该打印第2行 到目前为止,我还没有找到匹配字符串的确切方法 import gzip import csv, io

我正在尝试打印excel中4列的值。我需要匹配第4列中的一个特定字符串,然后只打印包含该字符串的行。(例如:如果第二行的第四列包含“Sweet”,我将打印整行)

excel示例:

name; number; fruit;  comment
test1 ;1   ;  apple ; healthy
test2; 2;     banana ;sweet and healthy
这里应该打印第2行

到目前为止,我还没有找到匹配字符串的确切方法

import gzip
import csv, io

with gzip.open("/test.csv.gz", "r") as file:
      datareader = csv.reader(file)

      included_cols = [9, 10, 11]
      for row in datareader:
        content = list(row[i] for i in included_cols if row[i])
        print content

利用您正在使用范围(9到11)的事实:


您的代码不是有效的Python。请回答您的问题,并修正缩进。好的。但是为什么
行[10]
with gzip.open("/test.csv.gz", "r") as file: datareader = csv.reader(file)
    datareader = csv.reader(file)
    for row in datareader:
        if 'Sweet' in row[9:12]:
            print(row[9:12])