【发布时间】:2019-09-25 19:49:02
【问题描述】:
感谢您花时间在这里提供帮助,我真的很感激。
目前,我有多个 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)
我被困在我上面评论过的区域,说我不确定如何执行该步骤..
【问题讨论】:
-
您是否尝试过使用pandas 读取excel 方法,而不是使用pandas 方法(寻找缩写列等)?
-
@EzerK 不,我没有尝试过使用 pandas,因为我对它的了解不多,而且我已经开始使用 openpyxl。这对熊猫来说可行吗?因为我担心熊猫无法读取列,除非它是工作表的第一行
-
这是 pandas 的经典任务(不是你说这是唯一的方法)看看 pandas 阅读 excel 文档
标签: python excel python-3.x