load a certain number of rows from csv with numpy

前端 未结 3 2034
梦毁少年i
梦毁少年i 2021-01-14 15:43

I have a very long file and I only need parts, a slice, of it. There is new data coming in so the file will potentially get longer.

To load the data from the CSV I u

3条回答
  •  温柔的废话
    2021-01-14 16:05

    Following this example, you should be able to use itertools.islice, without needing imap, map or csv.reader:

    import numpy as np
    import itertools
    
    with open('sample.txt') as f:
        # this will skip 100 lines, then read the next 50
        d=np.genfromtxt(itertools.islice(f,100,150),delimiter=',',usecols={cols})
    

提交回复
热议问题