Pandas._excel — Pandas 1.4.3 Documentation
Có thể bạn quan tâm
Site Navigation
- Getting started
- User Guide
- API reference
- Development
- Release notes
- GitHub
- Mastodon
Site Navigation
- Getting started
- User Guide
- API reference
- Development
- Release notes
- GitHub
- Mastodon
- Input/output
- pandas.read_pickle
- pandas.DataFrame.to_pickle
- pandas.read_table
- pandas.read_csv
- pandas.DataFrame.to_csv
- pandas.read_fwf
- pandas.read_clipboard
- pandas.DataFrame.to_clipboard
- pandas.read_excel
- pandas.DataFrame.to_excel
- pandas.ExcelFile
- pandas.ExcelFile.book
- pandas.ExcelFile.sheet_names
- pandas.ExcelFile.parse
- pandas.io.formats.style.Styler.to_excel
- pandas.ExcelWriter
- pandas.read_json
- pandas.json_normalize
- pandas.DataFrame.to_json
- pandas.io.json.build_table_schema
- pandas.read_html
- pandas.DataFrame.to_html
- pandas.io.formats.style.Styler.to_html
- pandas.read_xml
- pandas.DataFrame.to_xml
- pandas.DataFrame.to_latex
- pandas.io.formats.style.Styler.to_latex
- pandas.read_hdf
- pandas.HDFStore.put
- pandas.HDFStore.append
- pandas.HDFStore.get
- pandas.HDFStore.select
- pandas.HDFStore.info
- pandas.HDFStore.keys
- pandas.HDFStore.groups
- pandas.HDFStore.walk
- pandas.read_feather
- pandas.DataFrame.to_feather
- pandas.read_parquet
- pandas.DataFrame.to_parquet
- pandas.read_orc
- pandas.DataFrame.to_orc
- pandas.read_sas
- pandas.read_spss
- pandas.read_sql_table
- pandas.read_sql_query
- pandas.read_sql
- pandas.DataFrame.to_sql
- pandas.read_gbq
- pandas.read_stata
- pandas.DataFrame.to_stata
- pandas.io.stata.StataReader.data_label
- pandas.io.stata.StataReader.value_labels
- pandas.io.stata.StataReader.variable_labels
- pandas.io.stata.StataWriter.write_file
- General functions
- Series
- DataFrame
- pandas arrays, scalars, and data types
- Index objects
- Date offsets
- Window
- GroupBy
- Resampling
- Style
- Plotting
- Options and settings
- Extensions
- Testing
- Missing values
- API reference
- Input/output
- pandas.DataF...
Write object to an Excel sheet.
To write a single object to an Excel .xlsx file it is only necessary to specify a target file name. To write to multiple sheets it is necessary to create an ExcelWriter object with a target file name, and specify a sheet in the file to write to.
Multiple sheets may be written to by specifying unique sheet_name. With all data written to the file it is necessary to save the changes. Note that creating an ExcelWriter object with a file name that already exists will result in the contents of the existing file being erased.
Parameters: excel_writerpath-like, file-like, or ExcelWriter objectFile path or existing ExcelWriter.
sheet_namestr, default ‘Sheet1’Name of sheet which will contain DataFrame.
na_repstr, default ‘’Missing data representation.
float_formatstr, optionalFormat string for floating point numbers. For example float_format="%.2f" will format 0.1234 to 0.12.
columnssequence or list of str, optionalColumns to write.
headerbool or list of str, default TrueWrite out the column names. If a list of string is given it is assumed to be aliases for the column names.
indexbool, default TrueWrite row names (index).
index_labelstr or sequence, optionalColumn label for index column(s) if desired. If not specified, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.
startrowint, default 0Upper left cell row to dump data frame.
startcolint, default 0Upper left cell column to dump data frame.
enginestr, optionalWrite engine to use, ‘openpyxl’ or ‘xlsxwriter’. You can also set this via the options io.excel.xlsx.writer or io.excel.xlsm.writer.
merge_cellsbool, default TrueWrite MultiIndex and Hierarchical Rows as merged cells.
inf_repstr, default ‘inf’Representation for infinity (there is no native representation for infinity in Excel).
freeze_panestuple of int (length 2), optionalSpecifies the one-based bottommost row and rightmost column that is to be frozen.
storage_optionsdict, optionalExtra 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.
Added in version 1.2.0.
engine_kwargsdict, optionalArbitrary keyword arguments passed to excel engine.
See also
to_csvWrite DataFrame to a comma-separated values (csv) file.
ExcelWriterClass for writing DataFrame objects into excel sheets.
read_excelRead an Excel file into a pandas DataFrame.
read_csvRead a comma-separated values (csv) file into DataFrame.
io.formats.style.Styler.to_excelAdd styles to Excel sheet.
Notes
For compatibility with to_csv(), to_excel serializes lists and dicts to strings before writing.
Once a workbook has been saved it is not possible to write further data without rewriting the whole workbook.
Examples
Create, write to and save a workbook:
>>> df1 = pd.DataFrame([['a', 'b'], ['c', 'd']], ... index=['row 1', 'row 2'], ... columns=['col 1', 'col 2']) >>> df1.to_excel("output.xlsx")To specify the sheet name:
>>> df1.to_excel("output.xlsx", ... sheet_name='Sheet_name_1')If you wish to write to more than one sheet in the workbook, it is necessary to specify an ExcelWriter object:
>>> df2 = df1.copy() >>> with pd.ExcelWriter('output.xlsx') as writer: ... df1.to_excel(writer, sheet_name='Sheet_name_1') ... df2.to_excel(writer, sheet_name='Sheet_name_2')ExcelWriter can also be used to append to an existing Excel file:
>>> with pd.ExcelWriter('output.xlsx', ... mode='a') as writer: ... df1.to_excel(writer, sheet_name='Sheet_name_3')To set the library that is used to write the Excel file, you can pass the engine keyword (the default engine is automatically chosen depending on the file extension):
>>> df1.to_excel('output1.xlsx', engine='xlsxwriter') On this page- DataFrame.to_excel()
Từ khóa » Thư Viện Openpyxl
-
Thư Viện Openpyxl - VinaSupport
-
Openpyxl - A Python Library To Read/write Excel 2010 Xlsx/xlsm Files ...
-
Python Với Excel - Mở đầu Và Cài đặt Thư Viện
-
Cách Chỉnh Sửa Bảng Tính Excel Bằng Python Và Openpyxl
-
Đọc File Excel Trong Python
-
Tài Liệu Lập Trình Python - GitHub
-
Cách Cài đặt Openpyxl Bằng Pip - HelpEx
-
Openpyxl - Chỉ đọc Một Cột Từ Tệp Excel Trong Python?
-
Thiết Lập Tự động Hóa Python Excel: 5 Bước đơn Giản
-
Thiết Lập Tự động Hóa Python Excel: 5 Bước đơn Giản » - Inda
-
Mình Dùng Openpyxl Và Mình đang Viết Data Vào 1 Sheet | Facebook
-
Cách Thiết Lập Tự động Hóa Excel Bằng Python Từng Bước - Morioh
-
ad_excel — Pandas 1.4.3 Documentation
-
Openpyxl | Vietdecamnhan