[Python] python file to process excel sections not working

Discussão em 'Python' iniciado por Stack, Novembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I have an excel file with different sections, each one with its header, of which i provide its names (they also have a number attached to it on second column). On a first approach, i want to read and print on screen each section's cells. Here is the code I used:

    section_headers = [ 'LIBROS', 'CAPÍTULOS DE LIBROS','ARTÍCULOS CIENTÍFICOS (ORIGINALES Y DE REVISIÓN)', 'ARTÍCULOS DE DIVULGACIÓN','PONENCIAS PRESENTADAS','CARTELES PRESENTADOS EN CONGRESOS', 'CURSOS IMPARTIDOS','SEMINARIOS IMPARTIDOS','PROGRAMAS DE RADIO Y TV','PODCASTS','SOFTWARE', 'PATENTES', 'MODELOS DE UTILIDAD', 'PROTOTIPO', 'PRÁCTICAS PROFESIONALES', 'SERVICIO SOCIAL', 'TESIS','OTROS (Ej. Manuales, procesos)']

    def process_excel(file_path, section_headers):
    df = pd.read_excel(file_path, skiprows=2)


    sections = {}
    current_section = None
    section_data = []


    for idx, row in df.iterrows():

    if any(header in str(row[0]) for header in section_headers) and isinstance(row[1], (int, float)):
    if current_section is not None:
    sections[current_section] = pd.DataFrame(section_data)

    current_section = row[0] # The first column is the section name
    section_data = [] # Reset data for the new section

    else:
    # Add row data to current section
    section_data.append(row)


    if current_section is not None:
    sections[current_section] = pd.DataFrame(section_data)


    for section, data in sections.items():
    print(f"\nSection: {section}")
    print(data)


    Now, when I call the function:

    process_excel(file_path='wherever the file is", section_headers)


    i obtain nothing. I am running it on google colab. I already charged pandas and openpyxl. Any ideas on why i don't see anything (not even a error message)?

    Continue reading...

Compartilhe esta Página