python中cell对象find,使用openpyxl查找包含具有特定值的单元格的行(Python 3.6)

I am completely new to openpyxl so, as you can imagine, I am having pretyy hard times when I try to make use of it.

I have an excel report that contains only one sheet (called Sheet 1). I'd like to search all cells for those that contain specific string (product name ABC in this case).

Then I would like to copy contents of every cell in the rows that contain cell with ABC product name. And assign every cell to a variable.

To give you better idea of what I am trying to achieve I'll give you an example:

db1f99e1b4cb3381a9d0c9d285c4a79e.png

So in this case I would only copy cells from rows: 2, 4, 6 (as only they contain ABC product).

I have already looked up similar questions and answers to them but I don't understand them (never have used excel before).

解决方案

is it important for you to use openpyxl to do this? i would suggest using pandas if not.

import pandas as pd

df = pd.read_excel("path_to_excel_file")

df_abc = df[df["Products"] == "ABC"] # this will only contain 2,4,6 rows

then:

for row in df_abc.iterrows():

# do what you want with the row

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值