Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of dealing with 100tables with Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you an example analysis of using Python to deal with 100 forms. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

A story gives motivation.

No motivation to learn Python? Let a story give you motivation to learn! The takeout guy processes 100 forms in 10 minutes. Why does it take 10 minutes to process 100 forms? The story begins by summarizing 100 tables for an urgent customer need. The boss asks you to do it in 10 minutes, but if you do it the traditional way, 10 minutes is just the beginning.

The boss wants you to finish it in 10 minutes.

The head of the department was worried and went to the side to urge him. I'm not calm anymore!

The department leader is in a hurry.

At this time, the takeout boy who came to deliver the order went into battle and took care of it all with Python.

The takeout boy is in the game.

The end of the story leads to the content of this study. Excel is everywhere. For better or worse, it is basically the default application for data analysis in the workplace. You may need to perform many boring tasks in your daily work, which makes you think: "there must be a better way." Python is the artifact that can quickly process data tables! Not to mention a hundred copies, it's no problem to process thousands of data in a short time!

Process thousands of data in a short time

Programming idea

You can easily combine Excel workbooks with Python using the openpyxl library.

Install the library for Python

You can install openpyxl using pip or conda:

Pip install openpyxl conda install openpyxl

Count 100 files with less than 10 lines of code

Suppose that in each Excel workbook, there are totals in each row, but there are no sales totals. Similarly, you can open each workbook and add a formula, or you can use Python to do this! Openpyxl will be used. If you need to install, please check the instructions above. A link to download the file is also provided above.

Import openpyxl files = ["/ tmp/1.xlxs", "/ tmp/2.xlxs"] # excel path to be counted for file in files: wb = openpyxl.load_workbook (file) sheet = wb ['Sheet1'] sheet [' F9'] ='= SUM (F5:F8) 'sheet [' F9']. Style = 'Currency' wb.save (file)

In this code, fill in the list of files. The for loop opens each file and assigns "Sheet1" to the variable table. Then, assign the string'= SUM (F5:F8)'to cell F9 and use the .style property to assign the currency style directly to that cell. More cell styles can be found in the official documentation.

Conclusion: using Python office automation has become a trend.

Python makes working with Excel files very easy

Python makes working with Excel files very easy! In this article, the takeout guy used the actual handler to learn how to combine various Excel files, get specific values, and add formulas between workbooks. Although you may be using Excel workbooks all day, learning Python can automate tasks for a large number of excel files that cannot be done manually in a short period of time. In this story, the takeout boy uses the Python he learned to complete the task that should have been done by office white-collar workers. No matter the type of work, we all have a beautiful ideal, for the ideal, stand up to learn Python!

Of course, there are at least 5 ways to accomplish this task, and you can post the best ones in the post-comments section.

The above is the example analysis of using Python to deal with 100 tables shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report