def iter_loadtxt(filename, delimiter=',', skiprows=0, read_range=None,
    dtype=float):
    """
    Read the file line by line and convert it to Numpy array.
    :param delimiter: character
    :param skiprows : int
    :param read_range: [int, int] or None. set it to None and the function will read the whole file.
    :param dtype: type
    """

def iter_func():
    with open(filename, 'r') as infile:
        for _ in range(skiprows):
            next(infile)
if read_range is None:
    for line in infile:
        line = line.rstrip().split(delimiter)
for item in line:
    yield dtype(item)
else:
    counter = 0
for line in infile:
    if counter < read_range[0]:
        counter += 1
else:
    counter += 1
for item in line:
    yield dtype(item)
if counter >= read_range[1]:
    break
iter_loadtxt.rowlength = len(line)
data = np.fromiter(iter_func(), dtype=dtype)
data = data.reshape((-1, iter_loadtxt.rowlength))
return data
reading rows of big csv file in python