phillyooo phillyooo - 10 months ago 77
R Question

Importing csv file with line breaks to R or Python Pandas

I have a csv file that includes line breaks within columns:


ID 3, for example contains such a line break.

How can this be imported into python or R? Also, I don't mind if those line breaks were to be replaced by a space, for example.

Answer Source

Python has built-in CSV reader which handles that for you. See csv documentation.

import csv

with open(filename) as f:
    reader = csv.reader(f)
    csv_rows = list(reader)