在Python中,每1000行迭代一次文本文件

在Python中,每1000行迭代一次文本文件,python,pandas,iteration,Python,Pandas,Iteration,我想迭代一个文本文件的每1000行。我曾经对数据库做过类似的事情,在那里,我首先为每1000行编写一个新id,并对其进行迭代。现在我想用文本文件本身来做。有什么类似蟒蛇的方法吗?我只来了这么远 import pandas as pd input_file = 'text.csv' my_input = pd.read_csv(input_file, sep = ';') length = my_input.shape[0] start = 0 end = 999 #for the length

我想迭代一个文本文件的每1000行。我曾经对数据库做过类似的事情,在那里,我首先为每1000行编写一个新id,并对其进行迭代。现在我想用文本文件本身来做。有什么类似蟒蛇的方法吗?我只来了这么远

import pandas as pd

input_file = 'text.csv'
my_input = pd.read_csv(input_file, sep = ';')
length = my_input.shape[0]
start = 0
end = 999
#for the length of the whole document take the lines in range(start,end)
   do stuff
   start =+ 1000
   end =+ 1000

它似乎与blaze图书馆合作

import pandas as pd

input_file = 'text.csv'  
my_input = pd.read_csv(input_file, sep = ';', names=['a', 'b', 'c']
for chunk in blaze.odo(my_input, target=bz.chunks(pd.DataFrame), chunksize=1000):
    for index, row in chunk.iterrows():
            variable1 = row['a']
            variable1 = row['b']
            do stuff

首先,您需要决定是按原样读取文件、以csv文件的形式读取文件,还是使用其数据帧表示。@DeepSpace我需要每行的一些属性,因此我想在某个时候需要数据帧。但是否可以先读取1000行,然后创建一个数据帧,这样我就可以读取属性?