Pass regex to delimiter field in python's csv module or numpy's genfromtxt / loadtxt?

后端 未结 1 1928
逝去的感伤
逝去的感伤 2021-01-18 22:46

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  te         


        
相关标签:
1条回答
  • 2021-01-18 23:22

    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)
    
    0 讨论(0)
提交回复
热议问题