reading csv files in scipy/numpy in Python

前端 未结 5 1783
轻奢々
轻奢々 2020-12-16 08:23

I am having trouble reading a csv file, delimited by tabs, in python. I use the following function:

def csv2array(filename, skiprows=0, delimiter=\'\\t\', ra         


        
5条回答
  •  粉色の甜心
    2020-12-16 08:39

    Likely it came from Line 27100 in your data file... and it had 12 columns instead of 16. I.e. it had:

    separator,1,2,3,4,5,6,7,8,9,10,11,12,separator
    

    And it was expecting something like this:

    separator,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,separator
    

    I'm not sure how you want to convert your data, but if you have irregular line lengths, the easiest way would be something like this:

    lines = f.read().split('someseparator')
    for line in lines:
        splitline = line.split(',')
        #do something with splitline
    

提交回复
热议问题