Using openpyxl to find rows that contain cell with specific value (Python 3.6)

前端 未结 4 2209
春和景丽
春和景丽 2021-02-10 16:24

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

4条回答
  •  庸人自扰
    2021-02-10 16:53

    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 
    

提交回复
热议问题