China Naming Network - Eight-character lottery - Self-taught Python: Splitting excel Tables according to Conditions

Self-taught Python: Splitting excel Tables according to Conditions

There are many kinds of fruits in the table below. I want to divide them into several tables according to the types of fruits, and each table shows a kind of fruit.

Use the following statement:

Import xlwings as xw.

Import pandas as pd

app = xw。 App(visible =True,add_book =False)

workbook = app . books . open(' e:\ \ table \ \ worksheet . xlsx ')。

Worksheet = workbook.sheets[' statistical table']

value = worksheet . range(' a 1 ')。 Option (pd. DataFrame,header = 1,index =False,expand ='table ')。 value

Data = value.groupby ('category') # Group data by' category'.

For idx, packet data:

New _ worksheet = workbook.sheets.add (idx) # Add a worksheet to the workbook and name it the current product name.

New worksheet ['a 1']. Option (index = false). Value = group # Adds data to the newly added worksheet.

workbook.save()

workbook.close()

app.quit()

The implementation results are as follows:

Successfully divided into three tables.

_ _ _ _ _ _ _ _ _ _ _ _ End _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _