Skip to content Skip to sidebar Skip to footer

Ignoring Certain Characters While Looping Through Csv Rows

Using this code to try and print each row in a csv: import csv f = open('export.csv') csv_f = csvkit.reader(f) for row in csv_f: print(row) Unfortunately, the csv file conta

Solution 1:

If you want to filter some "unprintable/weird" chars you can do this:

row= ["aaaaa \xae bbbbb","foo"]

filtered_row = ["".join(c if ord(c)<128else "." for c in s) for s inrow]
print(filtered_row)

result (all strange chars have been replaced by dots):

['aaaaa . bbbbb', 'foo']

Post a Comment for "Ignoring Certain Characters While Looping Through Csv Rows"