Loading a file into a numpy array with python

后端 未结 5 1182
庸人自扰
庸人自扰 2020-12-14 04:44

So I\'m very green with Python and am trying to learn by replicating some matlab code I\'ve written. I have a part where, in matlab, I load a data file that\'s tab-delimited

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 05:24

    There is a csv module in the standard library.

    See the documentation here

    >>> import csv
    >>> spamReader = csv.reader(open('eggs.csv', 'rb'), delimiter=' ', quotechar='|')
    >>> for row in spamReader:
    ...     print ', '.join(row)
    Spam, Spam, Spam, Spam, Spam, Baked Beans
    Spam, Lovely Spam, Wonderful Spam
    

提交回复
热议问题