This is the 18th day of my participation in the August Challenge

The table used in this paper is as follows:

Commodity information sheet

1. Set the export path

You can set the file export path to the. XLSX file path by adjusting the excel_writer value.

Import pandas as pd goods_df = pd.read_excel(r 'c :\Users\viruser.v-desktop\ desktop\ XLSX ') goods_df.to_excel(excel_writer='test.xlsx')Copy the code

result:

Save the front:

After the save:

Note: If the same export file has been opened locally, you cannot run the export code again. You need to close the local file and run the export code again.

2. Set the Sheet name

XLSX files have multiple sheets. The default name for a Sheet is “Sheet” followed by an Arabic number, usually ascending from 1. You can also change the default Sheet name by modifying the sheet_name parameter

XLSX ') goods_df.to_excel(excel_writer='test.xlsx', Sheet_name =' test file ')Copy the code

result:

Before running:

After the operation:

3. Set indexes

Index =False; index=False; index=False;

XLSX ') goods_df.to_excel(excel_writer='test.xlsx', Sheet_name =' test file ', index=False)Copy the code

result:

Set before:

After the Settings:

4. Set the columns to be exported

Sometimes a table has a large number of columns, and only part of the columns need to be exported. You can specify the columns to export by setting the columns parameter

XLSX ') goods_df.to_excel(excel_writer='test.xlsx', Sheet_name = 'test file, index = False, the columns = [' classification', 'name'])Copy the code

result:

Before setting up the exported column:

After setting up the export column: