pandas.io.parsers.TextFileReader.get_chunk#

TextFileReader.get_chunk(size=None)[source]#

Read the next chunk of rows from the file.

Convenience wrapper around TextFileReader.read() that defaults size to the chunksize passed to read_csv() or read_table(), and respects a configured nrows limit by raising StopIteration once it has been reached.

Parameters:
sizeint, optional

Number of rows to read in this chunk. Defaults to the chunksize passed when the reader was created.

Returns:
DataFrame

The next chunk of parsed rows.

Raises:
StopIteration

If nrows was set and has already been reached.

See also

TextFileReader.read

Read rows from the file into a DataFrame.

read_csv

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

Examples

>>> with pd.read_csv("data.csv", iterator=True) as reader:
...     first_five = reader.get_chunk(5)