Skip to main content
`Ctrl`+`K`

# pandas.io.parsers.TextFileReader

class pandas.io.parsers.TextFileReader(f, engine=None, **kwds)

  Iterator over chunks of a delimited text file.

  Returned by `read_csv()`, `read_table()`, and `read_fwf()` when `iterator=True` or `chunksize` is given. Not intended to be constructed directly by users.

  A `TextFileReader` can be iterated over to yield successive chunks as `DataFrame` objects, used as a context manager to ensure the underlying file handle is closed, or queried explicitly via `read()` and `get_chunk()`.

  Passed `dialect` overrides any of the related parser options.

  Parameters:
    f str, 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()`, or `read_fwf()`.

  See also

  `read_csv`

    Read a comma-separated values (csv) file into a DataFrame.

  `read_table`

    Read general delimited file into a DataFrame.

  `read_fwf`

    Read 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

  `close`() | Close the underlying file handle and parser engine.
  `get_chunk`([size]) | Read the next chunk of rows from the file.
  `read`([nrows]) | Read rows from the file into a `DataFrame`.