![](/img/trans.png)
[英]How to write to excel sheet only those rows which match the condition using Python pandas
[英]match a specific string in excel and print those rows using python
我正在尝试从Excel中的4列打印值。 我需要匹配第四列中的特定字符串,然后仅打印具有该字符串的行。 (例如:如果第二行的第四列包含“ Sweet”,则将打印整行)
excel样本:
name; number; fruit; comment
test1 ;1 ; apple ; healthy
test2; 2; banana ;sweet and healthy
在这里应该打印row2
到目前为止,我有这个,无法找到匹配字符串的确切方法。
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)的事实:
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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.