pandas.read_csv

pandas 3.1.1 · Input and output · function

Parse delimited text into a DataFrame. Use dtype for identifier columns and usecols or chunksize to limit the data read.

Call syntax

pd.read_csv(…) Full signature
pd.read_csv(
    filepath_or_buffer,
    *,
    sep=…,
    delimiter=…,
    header='infer',
    names=…,
    index_col=None,
    usecols=None,
    dtype=None,
    engine=None,
    converters=None,
    true_values=None,
    false_values=None,
    skipinitialspace=False,
    skiprows=None,
    skipfooter=0,
    nrows=None,
    na_values=None,
    keep_default_na=True,
    na_filter=True,
    skip_blank_lines=True,
    parse_dates=None,
    date_format=None,
    dayfirst=False,
    cache_dates=True,
    iterator=False,
    chunksize=None,
    compression='infer',
    thousands=None,
    decimal='.',
    lineterminator=None,
    quotechar='"',
    quoting=0,
    doublequote=True,
    escapechar=None,
    comment=None,
    encoding=None,
    encoding_errors='strict',
    dialect=None,
    on_bad_lines='error',
    low_memory=True,
    memory_map=False,
    float_precision=None,
    storage_options=None,
    dtype_backend=…,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
filepath_or_buffer Required
Positional or keyword
str, path object or file-like object

Pass a path, a URL, or an open file-like object such as StringIO.

sep Optional
Keyword only
str

Choose the field separator. The usual default is a comma. Use sep="\t" for tab-delimited text.

delimiter Optional
Keyword only
str

Alternative name for sep. Supply one of these arguments.

header Optional
Keyword only
Default 'infer'
int, Sequence of int, 'infer' or None

Use "infer" for the usual header behavior, None for absent headers, or zero-based row positions for header rows.

names Optional
Keyword only
Sequence of Hashable

Supply explicit names for labels, fields, or levels.

index_col Optional
Keyword only
Default None
Hashable, Sequence of Hashable or False

Identify the column or columns whose values should become the row index.

usecols Optional
Keyword only
Default None
Sequence of Hashable or Callable

Pass selected names, integer positions, or a callable that accepts each column name.

dtype Optional
Keyword only
Default None
dtype or dict of {Hashable : dtype}

Pass a dtype for all columns or a mapping such as {"id": "string"} to preserve identifiers with leading zeroes.

engine Optional
Keyword only
Default None
{'c', 'python', 'pyarrow'}

Choose "c", "python", or "pyarrow". Features differ between these parsers.

converters Optional
Keyword only
Default None
dict of {Hashable : Callable}

Map column labels or positions to conversion functions.

true_values Optional
Keyword only
Default None
list

Add source values that should become boolean True.

false_values Optional
Keyword only
Default None
list

Add source values that should become boolean False.

skipinitialspace Optional
Keyword only
Default False
bool

Set True to ignore spaces immediately after delimiters.

skiprows Optional
Keyword only
Default None
int, list of int or Callable

Skip selected input rows before creating the DataFrame.

skipfooter Optional
Keyword only
Default 0
int

Skip this many lines at the end of the input.

nrows Optional
Keyword only
Default None
int

Limit the number of rows to read or display.

na_values Optional
Keyword only
Default None
Hashable, Iterable of Hashable or dict of {Hashable : Iterable}

Choose additional missing markers for all fields or supply a dictionary of markers by column.

keep_default_na Optional
Keyword only
Default True
bool

Choose whether pandas' built-in missing strings are recognized along with custom markers.

na_filter Optional
Keyword only
Default True
bool

Set False to turn off recognition of empty fields and other NA markers.

skip_blank_lines Optional
Keyword only
Default True
bool

Skip empty lines when True. With False, those lines can produce rows with missing values.

parse_dates Optional
Keyword only
Default None
bool, None, list of Hashable

A list of column labels chooses columns to parse. True primarily attempts to parse the index.

date_format Optional
Keyword only
Default None
str or dict of column -> format

Specify datetime parsing or formatting directives such as "%Y-%m-%d".

dayfirst Optional
Keyword only
Default False
bool

Prefer the day before the month when interpreting ambiguous date text.

cache_dates Optional
Keyword only
Default True
bool

Reuse parsed dates when source values repeat.

iterator Optional
Keyword only
Default False
bool

Set True to get a TextFileReader for incremental reading.

chunksize Optional
Keyword only
Default None
int

Set a positive integer to get a TextFileReader that yields batches.

compression Optional
Keyword only
Default 'infer'
str or dict

Choose whether and how to compress or decompress data.

thousands Optional
Keyword only
Default None
str (length 1)

Identify the character separating groups of digits.

decimal Optional
Keyword only
Default '.'
str (length 1)

Identify the character used as the decimal mark.

lineterminator Optional
Keyword only
Default None
str (length 1)

Specify the character or string ending each record.

quotechar Optional
Keyword only
Default '"'
str (length 1)

Specify the character used to quote a delimited field.

quoting Optional
Keyword only
Default 0
{0, 1, 2, 3}

Choose a quoting rule using the csv module's quoting constants.

doublequote Optional
Keyword only
Default True
bool

Choose whether doubled quote characters denote a single quote inside a field.

escapechar Optional
Keyword only
Default None
str (length 1)

Specify the character that escapes an otherwise special character.

comment Optional
Keyword only
Default None
str (length 1)

Identify the comment character used when parsing text.

encoding Optional
Keyword only
Default None
str

Name a text encoding such as "utf-8".

encoding_errors Optional
Keyword only
Default 'strict'
str

Choose how to handle text that cannot be encoded or decoded.

dialect Optional
Keyword only
Default None
str or csv.Dialect

Supply a CSV dialect object or a registered dialect name to configure delimiters and quoting together.

on_bad_lines Optional
Keyword only
Default 'error'
{'error', 'warn', 'skip'} or Callable

Choose "error", "warn", "skip", or a callable supported by the selected engine.

low_memory Optional
Keyword only
Default True
bool

Allow the C parser to process the file in chunks internally. The result still contains all requested rows unless chunksize or iterator is set.

memory_map Optional
Keyword only
Default False
bool

Use memory mapping for an eligible file path.

float_precision Optional
Keyword only
Default None
{'high', 'legacy', 'round_trip'}

Choose the floating-point converter for the C engine.

storage_options Optional
Keyword only
Default None
dict

Pass storage-backend options such as connection settings or HTTP headers.

dtype_backend Optional
Keyword only
{'numpy_nullable', 'pyarrow'}

Choose nullable NumPy-backed dtypes or Arrow-backed dtypes.

Returns

DataFrame for a full read. TextFileReader when chunksize or iterator requests incremental reading.