[Python] replace CRLF characters in middle of row for unquoted csv file using python

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

  1. Stack

    Stack Membro Participativo

    I am receiving below sample data in a txt file from source. The file contains a header row which signifies how many columns are expected per row

    ID,First name,last name,description,birth date<CR/LF>
    1,Smith,John,Loves to skateboard,12/3/98<CR/LF>
    2,Johnson,Mike,Eats worms,2/14/75<CR/LF>
    3,Howard,Sally,Walks along the beach<CR/LF>
    Likes bike rides<CR/LF>
    Loves to cook,9/7/67<CR/LF>
    4,Doe,Jane,Restores classic cars,7/4/74<CR/LF>


    For line number 3 there are extra CR/LF characters inside the data itself causing it to span across multiple lines in the file. How to remove the additional CR/LF characters inside the data but not at the line ending using python.

    Continue reading...

Compartilhe esta Página