- API reference
- Input/output
- pandas.read_fwf
pandas.read_fwf#
- pandas.read_fwf(filepath_or_buffer,*,colspecs='infer',widths=None,infer_nrows=100,dtype_backend=<no_default>,iterator=False,chunksize=None,**kwds)[source]#
Read a table of fixed-width formatted lines into DataFrame.
Also supports optionally iterating or breaking of the fileinto chunks.
Additional help can be found in theonline docs for IO Tools.
- Parameters:
- filepath_or_bufferstr, path object, or file-like object
String, path object (implementing
os.PathLike[str]
), or file-likeobject implementing a textread()
function.The string could be a URL.Valid URL schemes include http, ftp, s3, and file. For file URLs, a host isexpected. A local file could be:file://localhost/path/to/table.csv
.- colspecslist of tuple (int, int) or ‘infer’. optional
A list of tuples giving the extents of the fixed-widthfields of each line as half-open intervals (i.e., [from, to[ ).String value ‘infer’ can be used to instruct the parser to trydetecting the column specifications from the first 100 rows ofthe data which are not being skipped via skiprows (default=’infer’).
- widthslist of int, optional
A list of field widths which can be used instead of ‘colspecs’ ifthe intervals are contiguous.
- infer_nrowsint, default 100
The number of rows to consider when letting the parser determine thecolspecs.
- dtype_backend{‘numpy_nullable’, ‘pyarrow’}, default ‘numpy_nullable’
Back-end data type applied to the resultant
DataFrame
(still experimental). Behaviour is as follows:"numpy_nullable"
: returns nullable-dtype-backedDataFrame
(default)."pyarrow"
: returns pyarrow-backed nullableArrowDtype
DataFrame.
Added in version 2.0.
- **kwdsoptional
Optional keyword arguments can be passed to
TextFileReader
.
- Returns:
- DataFrame or TextFileReader
A comma-separated values (csv) file is returned as two-dimensionaldata 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.
Examples
>>>pd.read_fwf('data.csv')