pandas.ExcelFile#
- class pandas.ExcelFile(path_or_buffer, engine=None, storage_options=None, engine_kwargs=None)[source]#
Class for parsing tabular Excel sheets into DataFrame objects.
See read_excel for more documentation.
- Parameters:
- path_or_bufferstr, bytes, pathlib.Path,
A file-like object, xlrd workbook or openpyxl workbook. If a string or path object, expected to be a path to a .xls, .xlsx, .xlsb, .xlsm, .odf, .ods, or .odt file.
- enginestr, default None
If io is not a buffer or path, this must be set to identify io. Supported engines:
xlrd,openpyxl,odf,pyxlsb,calamineEngine compatibility :xlrdsupports old-style Excel files (.xls).openpyxlsupports newer Excel file formats.odfsupports OpenDocument file formats (.odf, .ods, .odt).pyxlsbsupports Binary Excel files.calaminesupports Excel (.xls, .xlsx, .xlsm, .xlsb) and OpenDocument (.ods) file formats.
The engine xlrd now only supports old-style
.xlsfiles. Whenengine=None, the following logic will be used to determine the engine:- If
path_or_bufferis an OpenDocument format (.odf, .ods, .odt), then odf will be used.
- If
- Otherwise if
path_or_bufferis an xls format, xlrdwill be used.
- Otherwise if
- Otherwise if
path_or_bufferis in xlsb format, pyxlsb will be used.
- Otherwise if
- Otherwise if openpyxl is installed,
then
openpyxlwill be used.
Otherwise if
xlrd >= 2.0is installed, aValueErrorwill be raised.
Warning
Please do not report issues when using
xlrdto read.xlsxfiles. This is not supported, switch to usingopenpyxlinstead.- 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.Requestas header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded tofsspec.open. Please seefsspecandurllibfor more details, and for more examples on storage options refer here.- engine_kwargsdict, optional
Arbitrary keyword arguments passed to excel engine.
See also
DataFrame.to_excelWrite DataFrame to an Excel file.
DataFrame.to_csvWrite DataFrame to a comma-separated values (csv) file.
read_csvRead a comma-separated values (csv) file into DataFrame.
read_fwfRead a table of fixed-width formatted lines into DataFrame.
Examples
>>> file = pd.ExcelFile("myfile.xlsx") >>> with pd.ExcelFile("myfile.xls") as xls: ... df1 = pd.read_excel(xls, "Sheet1")
Attributes
Gets the Excel workbook.
Names of the sheets in the document.
Methods
close()close io if necessary
parse([sheet_name, header, names, ...])Parse specified sheet(s) into a DataFrame.