Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does python split excel according to a list of contents?

Shulou Source: shulou.com Published: 2022-06-01 21:25:30 10月03日 Update

This article mainly explains "python how to split excel according to a column of content", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "python how to split excel according to a column of content" bar!

Use python to divide a column into multiple excel according to content

We often encounter at work, similar to the table in the following picture, the leader asks you to screen out each department and set up a separate excel according to the format of "Finance Department .xlsx". If the data is less, what if you are asked to split it in the middle of the night if the amount of data is large?

1. Source code:

Import pandas as pd df1 = pd.read_excel (rascal C:\ Users\ dell\ Desktop\ 123.xlsxxexamples) DataList = list (df1.groupby (['department])) for IN_DATA in DataList: IN_DATA [1] .to _ excel (' CGUSERGUSEUSUSGUserUserUserUserUserUserUserUserUserUserUserUserLTUserLTUSUSLUTER'+ str (IN_DATA [0]) + '.xlsx', sheet_name=IN_DATA [0], index=False)

2. Explanation:

The function of reading excel in pandas library is mainly used here, followed by sorting by department, and then a new table is established in turn.

Matters needing attention

Raster C:\ Users\ dell\ Desktop\ 123.xlsx' is the absolute path of my file, and the place where the final result is generated is' CJV _ account'. The slash of the two paths is different because it has been said in the penetration that the difference between win system and linux system only needs to be converted by adding a r. Second, groupby (['department'] according to the title of the column in which the table is built separately according to your needs.

Thank you for reading, the above is the content of "python how to split excel according to a column of content". After the study of this article, I believe you have a deeper understanding of how python can split excel according to a column of content, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Content department learning data system path following figure two items functions places multiple that is regular meetings ideas situations documents articles slashes more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL OPPO Reno Linux Shulou Tech Info