谢谢你花时间在这里帮忙,我真的很感激。你知道吗
目前,我有多个excel文件循环通过。你知道吗
我只在C:D列中循环。如果该列有关键字“缩写”,我想提取该列中的所有值。 这是因为我的关键字可能存在于C列或D列中
或
导入excel文件后,以下是我如何循环浏览要扫描的列:
wb1 = load_workbook(join(dict_folder, file), data_only = True)
ws = wb1.active
for rowofcellobj in ws["C":"D"]:
for cellobj in rowofcellobj:
if cellobj.value == "Abbreviation":
# extract all words in that column but Idk how to execute this step or if my above steps are correct
if cellobj.value is not None:
data = re.findall(r"\b\w+_.*?\w+|[A-Z]*$\b", str(cellobj.value))
#filtering out blank rows here:
if data != [ ]:
if data != [' ']:
#extracting words from square brackets in list:
fields = data[0]
print(fields)
我被困在我上面评论的区域,说我不知道如何执行这一步。。你知道吗
熊猫解决方案,灵感来自(link)
示例文件:
结果:
定义起始行,在这里
1
:循环所有行,从
min_row
开始递增:try
要在row
中查找关键字,如果找到break
。因为
index
是0-based
,所以+1
得到列索引1-based
。你知道吗如果找到,则循环所有folloup行,直至结束。你知道吗
相关问题 更多 >
编程相关推荐