[Python] Delete or remove last column in CSV file using Python

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

  1. Stack

    Stack Membro Participativo

    I have a CSV file with 5 columns. Using Python, how can I delete the last column (header5 in the example)? Is there an easy way I'm missing, or do I have to loop through all rows in the CSV and remove each value from the last column (which could still leave me with the undesired preceding comma)?

    I'm not seeing anything related to this in the CSV module or elsewhere on the interwebs, so any help is much appreciated.

    header1,header2,header3,header4,header5
    value1,value2,value3,value4,value5
    value1,value2,value3,value4,value5

    Continue reading...

Compartilhe esta Página