pandas.io.parsers.TextFileReader#
- class pandas.io.parsers.TextFileReader(f, engine=None, **kwds)[source]#
Iterator over chunks of a delimited text file.
Returned by
read_csv(),read_table(), andread_fwf()wheniterator=Trueorchunksizeis given. Not intended to be constructed directly by users.A
TextFileReadercan be iterated over to yield successive chunks asDataFrameobjects, used as a context manager to ensure the underlying file handle is closed, or queried explicitly viaread()andget_chunk().Passed
dialectoverrides any of the related parser options.- Parameters:
- fstr, path object, or file-like object
Source to read from. Accepts the same inputs as
read_csv().- engine{‘c’, ‘python’, ‘pyarrow’, ‘python-fwf’}, optional
Parser engine to use. If not specified, defaults to
'python'.- **kwds
Any keyword argument accepted by
read_csv(),read_table(), orread_fwf().
See also
read_csvRead a comma-separated values (csv) file into a DataFrame.
read_tableRead general delimited file into a DataFrame.
read_fwfRead a table of fixed-width formatted lines into a DataFrame.
Examples
>>> with pd.read_csv("data.csv", chunksize=1000) as reader: ... for chunk in reader: ... process(chunk)
>>> with pd.read_csv("data.csv", iterator=True) as reader: ... first = reader.get_chunk(5)
Methods