I have a CSV, which has got three different delimiters namely, \'|\', \',\' and \';\' between different columns.
How can I using Python parse this CSV ?
My
Sticking with the standard library, re.split() can split a line at any of these characters:
import re
with open(file_name) as fobj:
for line in fobj:
line_data = re.split('Delim_first|Delim_second|[|]', line)
print(line_data)
This will split at the delimiters |, Delim_first, and Delim_second.
Or with pandas:
import pandas as pd
df = pd.read_csv('multi_delim.csv', sep='Delim_first|Delim_second|[|]',
engine='python', header=None)
Result: