I have tabulated data with some strange delimination (i.e. groups of values separated by commas, seperated from other values by tabs):
A,345,567 56 67 test
Is there a clean and clever way of handling multiple delimiters in any of the following: csv module, numpy.genfromtxt, or numpy.loadtxt?
I have found methods such as this, but I'm hoping there is a better solution out there. Ideally I'd like to use a genfromtxt and a regex for the delimiter.
I’m afraid the answer is no in the three packages you asked for. However, you can just do replace('\t', ',')
(or the reverse). For example:
from StringIO import StringIO # py3k: from io import StringIO
import csv
with open('./file') as fh:
io = StringIO(fh.read().replace('\t', ','))
reader = csv.reader(io)
for row in reader:
print(row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With