[Python] How do I dynamically filter my excel workbook using Python (without using VBA)

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the xlsxwriter library to preform some formatting on my pandas dataframe. Now I'm trying to create a drop down filter and link it to the entire dataset. So for example, one of my columns is "Cabin". I eventually want to hide Cabin from the table and instead have it as a drop down filer. So when the user selects a Cabin type (eco/bus) the entire dataset will be filtered according to that cabin type. I managed to create the dropdown. Now how do I link it to my data?

    # Drop down menu
    # Extract unique values from the Cabin column for the dropdown
    unique_cabins = df['Cabin'].unique()

    # Write the word "Cabin" in cell A4
    worksheet.write('A4', 'Cabin',bordered_format)

    # Create a dropdown list in cell A4
    worksheet.data_validation('A4', {
    'validate': 'list',
    'source': unique_cabins.tolist(),
    })

    Continue reading...

Compartilhe esta Página