Delimited-file ingestion
Import a tab-separated log, export, or dataset into a DataFrame.
Pandas · Function
Reads a general delimited text file or file-like object into a pandas DataFrame, using tab separation by default. It can also expose incremental chunked parsing for large inputs.
Use read_table to parse a delimited text file or file-like object into a DataFrame. Configure the separator, column labels, types, missing-value handling, date parsing, encoding, and chunked iteration through keyword arguments.
pandas.read_table(filepath_or_buffer, *, sep=<no_default>, delimiter=None, header='infer', names=<no_default>, 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=<no_default>)| Name | Type | Description |
|---|---|---|
filepath_or_buffer | str, path object, or file-like object | Path, URL, or file-like object containing the delimited data. |
sep | str or regex-like | Delimiter used to split fields; the default is a tab. |
header | int, list-like, or 'infer' | Column names or positions to use as the header. |
names | array-like | Optional names for the resulting columns. |
index_col | int, str, sequence, or False | Column(s) to use as the row index. |
usecols | list-like or callable | Subset of columns to read. |
dtype | Dtype, mapping, or None | Column data types, globally or per column. |
na_values | scalar, str, list-like, or dict | Values to recognize as missing, in addition to or instead of defaults. |
keep_default_na | bool | Whether to include pandas' default missing-value markers. |
na_filter | bool | Whether to detect missing-value markers. |
parse_dates | bool, list-like, or dict | Columns to parse as dates. |
chunksize | int, optional | Number of rows per iteration; enables chunked reading. |
DataFrame or TextFileReader. A DataFrame is returned for ordinary reads; iterator or chunked operation returns a text parser for incremental consumption.
iterator=True or chunksize changes the result from an immediately materialized DataFrame to chunk-oriented parsing.import io
import pandas as pd
text = "name\tage\nAda\t36\nLinus\t55\n"
df = pd.read_table(io.StringIO(text), sep="\t")
print(df)
Reads tab-separated text from an in-memory file-like object into a DataFrame.
Import a tab-separated log, export, or dataset into a DataFrame.
Read only required fields from a wide text file.
Process a dataset larger than available memory in batches.
Convert selected text fields into datetime or controlled pandas dtypes while parsing.
pandas.read_table return?read_table reads a general delimited file into a DataFrame. It accepts a path, URL, or file-like object through filepath_or_buffer, and defaults to tab separation.
Follow-up: How would you process a file that does not fit in memory? Set chunksize or use iterator=True, then consume the resulting text parser in pieces.
sep selects the delimiter, while header and names control column labels. usecols restricts the columns read, and dtype supplies desired column types.
Follow-up: How can parsing be made more memory-efficient? Select only needed columns with usecols, provide suitable dtypes, and use chunking when necessary.
Missing-value recognition is controlled by na_values, keep_default_na, and na_filter. Date conversion can be requested with parse_dates, with formatting controlled by date_format.
Follow-up: How would you avoid interpreting a token as missing? Disable default missing-value recognition or adjust the supplied na_values configuration.
pandas.read_csvpandas.read_fwfpandas.DataFramepandas.io.parsers.readers.TextFileReader