Take stock of a Python automation office case sharing

Click on " Python Crawler and Data Mining " above to pay attention

Reply to " Books " to get a total of 10 e-books on Python from entry to advanced

now

Day

chicken

Soup

The formalities of the low-brow letter continued, telling the infinite things in my heart.

Hello everyone, I am Pippi.

I. Introduction

A few days ago, I asked a Pythonquestion about office automation in the Python strongest king group [Don't get angry], and I will share it with you here.

In his original data, as shown in the figure below, here is the processing after desensitization:

1258c3b7e83999be89d2b526adb34d17.png

It turns out that what fans do is, for different contract numbers, which belong to different products, he screens the data independently from excel. For example, contract 1 is a separate form, contract 2 is a separate form, and contract 3 is a separate form. Separate tables, and then separate operations for 3 different tables.

The above approach is indeed feasible, but screening is time-consuming and energy-intensive. If something goes wrong, such as copying less than one line, it is easy to cause confusion.

2. Implementation process

In fact, you can add a judgment when processing here. If it is contract 1, write a processing function for contract 1 separately. Similarly, if it is contract 2, write a processing function for contract 2 separately, and so on. . After all, each contract represents a different product, and there are still some differences in the template processing of each product.

Then the public part can still be reused. In the past, the three programs needed to be run separately, but now they are integrated into one code file, which improves the efficiency.

if __name__ == '__main__':
    df = pd.read_excel("测试数据.xlsx", sheet_name="Sheet1", usecols="B,E,F,M,Q,R,U,V,X,AC,AN:AR")
    df.columns = [c.strip() for c in df.columns]
    for (b, e, m, f), df_split in df.groupby(['合同号', '商品编号', '收货单位', "城市名"]):
        m = m.strip("*")
        # 注意这里会过滤掉特殊省位
        if any(addr in f for addr in ("广东", "安徽", "浙江", "福建", "贵州")):
            continue
        if b.startswith("合同1"):
            title = "合同1"
            hetong1(title, e)

        elif b.startswith("合同2"):
            title = "合同2"
            hetong2(title, e)

        elif b.startswith("合同3"):
            title = "合同3"
            hetong3(title, e)

        else:
            print(f"该订单{b}属于其他产品!")

After the program was improved, it successfully helped fans solve the problem, and also improved the efficiency of dealing with the problem. The fans called it a good guy!

3. Summary

Hello everyone, I am Pippi. This article mainly takes stock of a Pythonproblem in office automation. Aiming at this problem, the article gives specific analysis and code implementation to help fans solve the problem smoothly.

Finally, I would like to thank the fans [Mo Angry] for asking questions, thank [Python Advanced] for the ideas and code analysis, and thank [Feng Cheng] and others for participating in the learning and exchange.

[Supplementary questions] Warm reminder, when you ask questions in the group. You can pay attention to the following points: if it involves large file data, you can desensitize the data, send some demo data (meaning small files), and then paste some code (the kind that can be copied), and remember to send the screenshot of the error report (complete cut ). If there are not many codes, just send the code text directly. If the code exceeds 50 lines, just send a .py file.

94041b2e79cca08e959701f38b6d8ec0.png

If you have any problems during the learning process, please feel free to contact me to solve them (my WeChat: pdcfighting1). At the request of fans, I have created some high-quality Python paid learning exchange groups and paid order receiving groups. Welcome everyone to join me Python learning exchange group and order receiving group!

b0613cbebf42978e293318d5cfe2f140.png

Friends, hurry up and practice it! If you encounter any problems during the learning process, please add me as a friend, and I will pull you into the Python learning exchange group to discuss learning together.

0397ebb4ba73af72fff23719eebedb1f.jpeg

------------------- End -------------------

Recommendations for past wonderful articles:

5b3a2b9eba34a41e58c3e03076b718e7.png

Welcome everyone to like, leave a message, forward, repost, thank you for your company and support

If you want to join the Python learning group, please reply in the background [ join the group ]

Thousands of rivers and thousands of mountains are always in love, can you click [ Looking ]

/Today's Message Topic/

Just say a few words~~

Guess you like

Origin blog.csdn.net/pdcfighting/article/details/131297877