[Python] Clear value on a specific column using openpyxl

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have 2 questions. And I want to solve do it on openpyxl since I already formatted my excel file and want to do the following.


    1. Remove all the duplicates only remain the first value


    2. Remove all the value on the Column A that have "Subtotal" in its value.

    For reference here is my data set

    Column_A Column_B Column_C
    1 A 10
    1 None 11
    1 None 12
    1_Subtotal None 33
    1_Subtotal_1 None 33


    Expected Outcome:

    Column_A Column_B Column_C
    1 A 10
    None None 11
    None None 12
    None None 33
    None None 33


    I tried using this code for removing the subtotal

    for cell in ws['Column_A']:
    if 'Subtotal' in str(cell.value):
    cell.value = None


    But it won't work. Thanks!

    Continue reading...

Compartilhe esta Página