load a certain number of rows from csv with numpy

前端 未结 3 1941
梦毁少年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:18

    Starting Numpy 1.10, np.genfromtxt takes an optional parameter max_rows which limits the number of lines to read.

    Combined with the other optional parameter skip_header, you can select a slice of your file (for instance lines 100 to 150):

    import numpy as np
    
    np.loadtxt('file.txt', skip_header=100, max_rows=50)
    

提交回复
热议问题