pandas.read_table(filepath_or_buffe
pandas.read_table(filepath_or_buffe
Parameters:
filepath_or_bufferstr, path object or file-like object
Any valid string path is acceptable. The string could be a URL. Valid URL schemes
include http, ftp, s3, gs, and file. For file URLs, a host is expected. A local
file could be: file://localhost/path/to/table.csv.
delimiterstr, optional
Alias for sep.
Note: index_col=False can be used to force pandas to not use the first column as
the index, e.g., when you have a malformed file with delimiters at the end of each
line.
If callable, the callable function will be evaluated against the column names,
returning names where the callable function evaluates to True. An example of a
valid callable argument would be lambda x: x.upper() in ['AAA', 'BBB', 'DDD'].
Using this parameter results in much faster parsing time and lower memory usage.
Added in version 1.5.0: Support for defaultdict was added. Specify a defaultdict as
input where the default determines the dtype of the columns which are not
explicitly listed.
Added in version 1.4.0: The ‘pyarrow’ engine was added as an experimental engine,
and some features are unsupported, or may not work correctly, with this engine.
true_valueslist, optional
Values to consider as True in addition to case-insensitive variants of ‘True’.
false_valueslist, optional
Values to consider as False in addition to case-insensitive variants of ‘False’.
If callable, the callable function will be evaluated against the row indices,
returning True if the row should be skipped and False otherwise. An example of a
valid callable argument would be lambda x: x in [0, 2].
skipfooterint, default 0
Number of lines at bottom of file to skip (Unsupported with engine='c').
nrowsint, optional
Number of rows of file to read. Useful for reading pieces of large files.
If keep_default_na is True, and na_values are not specified, only the default NaN
values are used for parsing.
If keep_default_na is False, and na_values are specified, only the NaN values
specified na_values are used for parsing.
bool. If True -> try parsing the index. Note: Automatically set to True if
date_format or date_parser arguments have been passed.
list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a
separate date column.
list of list. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single
date column. Values are joined with a space before parsing.
dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call result ‘foo’.
Values are joined with a space before parsing.
Deprecated since version 2.0.0: A strict version of this argument is now the
default, passing it has no effect.
date_parserCallable, optional
Function to use for converting a sequence of string columns to an array of datetime
instances. The default uses dateutil.parser.parser to do the conversion. pandas
will try to call date_parser in three different ways, advancing to the next if an
exception occurs: 1) Pass one or more arrays (as defined by parse_dates) as
arguments; 2) concatenate (row-wise) the string values from the columns defined by
parse_dates into a single array and pass that; and 3) call date_parser once for
each row using one or more strings (corresponding to the columns defined by
parse_dates) as arguments.
Deprecated since version 2.0.0: Use date_format instead, or read in as object and
then apply to_datetime() as-needed.
“mixed”, to infer the format for each element individually. This is risky,
and you should probably use it along with dayfirst.
chunksizeint, optional
Number of lines to read from the file per chunk. Passing a value will cause the
function to return a TextFileReader object for iteration. See the IO Tools docs for
more information on iterator and chunksize.
'warn', raise a warning when a bad line is encountered and skip that line.
'skip', skip bad lines without raising or warning when they are encountered.
Callable, function with signature (bad_line: list[str]) -> list[str] | None that
will process a single bad line. bad_line is a list of strings split by the sep. If
the function returns None, the bad line will be ignored. If the function returns a
new list of strings with more elements than expected, a ParserWarning will be
emitted while dropping extra elements. Only supported when engine='python'
storage_optionsdict, optional
Extra options that make sense for a particular storage connection, e.g. host, port,
username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to
urllib.request.Request as header options. For other URLs (e.g. starting with
“s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec.open. Please see
fsspec and urllib for more details, and for more examples on storage options refer
here.
Returns:
DataFrame or TextFileReader
A comma-separated values (csv) file is returned as two-dimensional data structure
with labeled axes.
See also
DataFrame.to_csv
Write DataFrame to a comma-separated values (csv) file.
read_csv
Read a comma-separated values (csv) file into DataFrame.
read_fwf
Read a table of fixed-width formatted lines into DataFrame.
Examples
pd.read_table('data.csv')