Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xlrd python 3.3解析excel中的关键字_Python_Excel_Parsing_Xlrd - Fatal编程技术网

使用xlrd python 3.3解析excel中的关键字

使用xlrd python 3.3解析excel中的关键字,python,excel,parsing,xlrd,Python,Excel,Parsing,Xlrd,我不熟悉excel文件的解析,我注意到我应该使用xlrd 我想把所有带有“predicted”关键字的行都拉出来 excel数组在sheet1上,它由4列(A-D)组成,我需要为包含关键字的行提取C列和D列(尽管如果更容易,整行可以工作) 这个文件超过1700行,是.xlsx,我正在使用python 3.3编写它 感谢您的帮助。以下内容将帮助您开始: import xlrd from operator import itemgetter keyword = "test" workbook =

我不熟悉excel文件的解析,我注意到我应该使用xlrd

我想把所有带有“predicted”关键字的行都拉出来

excel数组在sheet1上,它由4列(A-D)组成,我需要为包含关键字的行提取C列和D列(尽管如果更容易,整行可以工作)

这个文件超过1700行,是.xlsx,我正在使用python 3.3编写它


感谢您的帮助。

以下内容将帮助您开始:

import xlrd
from operator import itemgetter

keyword = "test"

workbook = xlrd.open_workbook(r"input.xlsx")
sheet = workbook.sheet_by_index(0)
rows = [sheet.row(row) for row in range(sheet.nrows)]   # Read in all rows

rows = [row for row in rows if keyword in ' '.join(str(col.value) for col in itemgetter(2, 3)(row))]    # Filter rows containing keyword somewhere

for row in rows:
    print(row)
它打开
xlsx
文件中的第一张工作表,并创建一个包含所有行的列表。对于每一行,它将所需列(
C
D
)中的所有单元格合并在一起,并检查关键字是否存在。如果是,则复制该行。最后,它显示所有匹配的行


注意,
中的数据仍然是
xlrd
格式,允许您对其进行进一步处理。

您尝试了什么?我要求人们为他们编写代码。如果你想在现有的代码上得到帮助,那完全是另一回事。公平会尽快给你回代码