Panda.read_csv function

Source: Internet
Author: User
Tags unsupported

Pandas.read_csv¶
Pandas. Read_csv ( Filepath_or_buffer, sep= ', ', Delimiter=none, header= ' infer ', Names=none, Index_col=none, Usecols=none, Squeeze=false, Prefix=none, mangle_dupe_cols=true, Dtype=none, Engine=none, Converters=none, True_values=none, False_values=none, Skipinitialspace=false, Skiprows=none, Skipfooter=none, Nrows=none, Na_values=none, keep_default_na=true, na_filter=true, Verbose=false, skip_blank_lines=true, Parse_dates=false, Infer_datetime_format=false, Keep_date_col=false, Date_parser=none, Dayfirst=false, Iterator=false, Chunksize=none, compression= ' infer ', Thousands=none, decimal= '. ', Lineterminator=none, quotechar= ' "', quoting=0, Escapechar=none, Comment=none, Encoding=none, Dialect=none, Tupleize_cols=false, error_bad_lines=true, warn_bad_lines=true, skip_footer=0, doublequote=true, Delim_whitespace=false, As_recarray=false, Compact_ints=false, Use_unsigned=false, low_memory=true, Buffer_lines=none, Memory_map=false, Float_precision=none

Read CSV (comma-separated) file into DataFrame

Also supports optionally iterating or breaking of the file into chunks.

Additional help can is found in the online docs for IO Tools.

Parameters:

filepath_or_buffer : str, pathlib. Path, Py._path.local.localpath or any object with a read () method (such as a file handle or Stringio)

The string could is a URL. Valid URL schemes include HTTP, FTP, s3, and file. For file URLs, a host is expected. For instance, a local file could is file://localhost/path/to/table.csv

Enter the appropriate address for the document.

Sep : str, default ', '

Delimiter to use. If Sep is None, would try to automatically determine this. Separators longer than 1 character and different from ' s+ ' would be interpreted as regular expressions, would force use of T He python parsing engine and would ignore quotes in the data. Regex example: ' RT '

Separator

delimiter : str, default None

Alternative argument name for Sep.

separators, with Sep

Delim_whitespace : boolean, default False

Specifies whether or not whitespace (e.g. " or " ) would be the use D as the SEP. Equivalent to setting sep= ' \+s '. If This option is set to True, nothing should being passed in for the delimiter parameter.

New in version 0.18.1: support for the Python parser.

header : int or List of ints, default ' infer '

Row number (s) to use as the column names, and the start of the data. Default behavior is as if set to 0 if no names passed, otherwise None. Explicitly pass header=0 to is able to replace existing names. The header can be a list of integers this specify row locations for a multi-index on the columns e.g. [0,1,3]. Intervening rows that was not specified would be skipped (e.g. 2 in this example is skipped). Note that this parameter ignores commented lines and empty lines if skip_blank_lines=true, so header=0 denotes th E first line of data rather than the first line of the file.

names : array-like, default None

List of column names to use. If file contains no header row, then you should explicitly pass Header=none

index_col : int or sequence or False, default None

Column to use as the row labels of the DataFrame. If a sequence is given, a multiindex is used. If you had a malformed file with delimiters at the end of each line, you might consider index_col=false to force pandas T o _not_ use the first column as the index (row names)

usecols : array-like, default None

Return a subset of the columns. All elements in this array must either is positional (i.e. integer indices into the document columns) or strings that Corr Espond to column names provided either by the user in names or inferred from the document header row (s). For example, a valid usecols parameter would be [0, 1, 2] or [' foo ', ' Bar ', ' Baz ']. Using This parameter results in much faster parsing time and lower memory usage.

Squeeze : boolean, default False

If The parsed data is contains one column then return a Series

prefix : str, default None

Prefix to add-to-column numbers when no headers, e.g. ' X ' for X0, X1, ...

Mangle_dupe_cols : boolean, default True

Duplicate columns would be specified as ' x.0 ' ... ' X.N ', rather than ' x ' ... ' x '

dtype : type name or dict of column, type, default None

Data type for data or columns. e.g. {' A ': Np.float64, ' B ': Np.int32} (Unsupported with engine= ' Python '). Use the str or object to preserve and not interpret dtype.

engine : {' C ', ' Python '}, optional

Parser engine to use. The C engine was faster while the Python engine was currently more feature-complete.

Converters : dict, default None

Dict of functions for converting values in certain columns. Keys can either be integers or column labels

true_values : list, default None

Values to consider as True

false_values : list, default None

Values to consider as False

Skipinitialspace : boolean, default False

Skip spaces after delimiter.

skiprows : List-like or integer, default None

Line numbers to skip (0-indexed) or number of lines to skip (int.) at the start of the file

skipfooter : int, default 0

Number of lines at bottom of "file to skip" (Unsupported with engine= ' C ')

nrows : int, default None

Number of rows of file to read. Useful for reading pieces of large files

na_values : str or list-like or dict, default None

Additional strings to recognize as Na/nan. If dict passed, specific per-column NA values. By default the following values is interpreted as NaN: ', ' #N/A ', ' #N/A N/a ', ' #NA ', ' -1. #IND ', ' -1. #QNAN ', '-nan ', '-nan ', ' 1. #IND ', ' 1. #QNAN ' , ' n/A ', ' NA ', ' NULL ', ' nan ', ' nan '.

keep_default_na : bool, default True

If Na_values is specified and Keep_default_na is False the default NaN values is overridden, otherwise they ' re appended To.

Na_filter : boolean, default True

Detect Missing value markers (empty strings and the value of na_values). In data without any NAs, passing na_filter=false can improve the performance of reading a large file

verbose : boolean, default False

Indicate number of NA values placed in Non-numeric columns

Skip_blank_lines : boolean, default True

If True, skip over blank lines rather than interpreting as NaN values

parse_dates : boolean or List of ints or names or list of lists or dict, default False

  • Boolean. If True, try parsing the index.

  • List of ints or names. e.g. If [1, 2, 3], try parsing columns 1, 2, 3 each as a separate date column.

  • List of lists. e.g. If [[1, 3]], combine columns 1 and 3 and parse as

    A single date column.

  • Dict, e.g. {' foo ': [1, 3]}, parse columns 1, 3 as date and call result ' foo '

Note:a Fast-path exists for iso8601-formatted dates.

Infer_datetime_format : boolean, default False

If True and Parse_dates is enabled, pandas would attempt to infer the format of the DateTime strings in the columns, and if It can be inferred, switch to a faster method of parsing them. In some cases this can increase the parsing speed by ~5-10x.

Keep_date_col : boolean, default False

If True and Parse_dates specifies combining multiple columns then keep the original columns.

date_parser : function, default None

Function to use for converting a sequence of the string columns to an array of datetime instances. The default uses Dateutil.parser.parser to do the conversion. Pandas would try to call Date_parser in three different ways, advancing to the next if a 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 to parse_dates into a single array and pass; and 3) Call Date_parser once for each row using one or more strings (corresponding to the columns defined by parse_dates) As arguments.

Dayfirst : boolean, default False

DD/MM format dates, international and European format

iterator : boolean, default False

Return Textfilereader object for iteration or getting chunks with get_chunk ().

chunksize : int, default None

Return Textfilereader object for iteration. See IO Tools Docs for more information on iterator and chunksize.

compression : {' infer ', ' gzip ', ' bz2 ', ' zip ', ' XZ ', None}, default ' infer '

For On-the-fly decompression of on-disk data. If ' infer ', then use gzip, bz2, zip or XZ if filepath_or_buffer are a string ending in '. Gz ', '. bz2 ', '. zip ', or ' xz ', resp Ectively, and no decompression otherwise. If using ' Zip ', the zip file must contain only one data file to is read in. Set to None for no decompression.

New in version 0.18.1: the support for ' zip ' and ' xz ' compression.

thousands : str, default None

Thousands Separator

decimal : str, default '. '

Character to recognize as decimal point (e.g. use ", ' for European data).

LineTerminator : str (length 1), default None

Character to break file into lines. Only valid with C parser.

QuoteChar : str (length 1), optional

The character used to denote the start and end of a quoted item. Quoted items can include the delimiter and it'll be ignored.

quoting : int or CSV. quote_* instance, default None

Control Field quoting behavior per CSV. Quote_* constants. Use one of Quote_minimal (0), Quote_all (1), Quote_nonnumeric (2) or Quote_none (3). Default (None) results in quote_minimal behavior.

Escapechar : str (length 1), default None

One-character string used to escape delimiter if quoting is Quote_none.

comment : str, default None

Indicates remainder of line should is not being parsed. If found at the beginning of a line, the line would be ignored altogether. This parameter must is a single character. Like empty lines (as long as skip_blank_lines=true), fully commented lines is ignored by the parameter Heade R but isn't by SkipRows. For example, if comment= ' # ', parsing ' #emptyna, b,cn1,2,3 ' with header=0 would result in ' a,b,c ' being treated as T He header.

encoding : STR, default None

Encoding to use for UTF when Reading/writing (ex. ' Utf-8 '). List of Python Standard encodings

dialect : STR or CSV. Dialect instance, default None

If None defaults to Excel dialect. ignored if Sep longer than 1 char see CSV. Dialect documentation for more details

Tupleize_cols : boolean, default False

Leave a list of tuples on columns as are (default is to convert to a Multi Index on the columns)

Error_bad_lines : boolean, default True

Lines with too many fields (e.g. a CSV line with too many commas) would by default cause an exception to be raised, and no DataFrame'll be returned. If False, then these "bad lines" would dropped from the DataFrame it is returned. (only valid with C parser)

Warn_bad_lines : boolean, default True

If Error_bad_lines is False, and Warn_bad_lines are True, a warning for each "bad line" would be output. (only valid with C parser).

Returns:

result : DataFrame or TextParser

Panda.read_csv function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.