6 Python office hacks to increase work efficiency by 100 times! (With code) python black technology

Preface

Getting off work late and working overtime for long periods of time have become common problems among modern workers. They waste most of their time on mechanical and repetitive tasks every day. How to improve your own work efficiency is the key.

Today I will share with you 6 Python office tips to double your work efficiency.You are welcome to learn, collect, like and support.

Without further ado, let’s start learning.

1. Parse PDF (resume recommendation)

Application scenario: Resume recommendation (parsed content: including but not limited to name, email, phone number, education and other information)

Input: File path to parse

Output: Content to be parsed

Environment preparation:python 3.6, mac (The conversion of doc to docx below is the mac writing method. Windows is simpler, just import the win32 package. )

Dependency packages:

from pdfminer.pdfparser import PDFParser

from pdfminer.pdfdocument import PDFDocument

from pdfminer.pdfpage import PDFPage

from pdfminer.pdfinterp import PDFResourceManager

from pdfminer.pdfinterp import PDFPageInterpreter

from pdfminer.layout import LAParams

from pdfminer.converter import PDFPageAggregator
 
def pdf_reader(file):
    fp = open(file, "rb")
    # 创建一个与文档相关联的解释器
    parser = PDFParser(fp)
    # PDF文档对象
    doc = PDFDocument(parser)
    # 链接解释器和文档对象
    parser.set_document(doc)
    # doc.set_paeser(parser)
    # 初始化文档
    # doc.initialize("")
    # 创建PDF资源管理器
    resource = PDFResourceManager()
    # 参数分析器
    laparam = LAParams()
    # 创建一个聚合器
    device = PDFPageAggregator(resource, laparams=laparam)
    # 创建PDF页面解释器
    interpreter = PDFPageInterpreter(resource, device)
    # 使用文档对象得到页面集合
    res = ''
    for page in PDFPage.create_pages(doc):
        # 使用页面解释器来读取
        interpreter.process_page(page)
        # 使用聚合器来获取内容
        layout = device.get_result()
        for out in layout:
            if hasattr(out, "get_text"):
                res = res + '' + out.get_text()
    return res


2. Send email

There are several modules for accessing the Internet and handling network communication protocols. The two simplest of these are urllib.request for handling data received from urls and smtplib for sending emails:

smtpObj = smtplib.SMTP( [host [, port [, local_hostname]]] )


Numerical explanation

  • host: SMTP server host. You can specify the IP address or domain name of the host such as: http://runoob.com. This is an optional parameter.
  • port: If you provide the host parameter, you need to specify the port number used by the SMTP service. Generally, the SMTP port number is 25.
  • local_hostname: If SMTP is on your local machine, you only need to specify the server address as localhost.

The Python SMTP object uses the sendmail method to send emails. The syntax is as follows:

SMTP.sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])


Numerical explanation

  • from_addr: Email sender address.
  • to_addrs: string list, email sending address.
  • msg: send message

Case:

from email.mime.text import MIMEText

from email.header import Header

sender = '[email protected]'

receivers = ['[email protected]']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

# 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码

message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')

message['From'] = Header("不吃西红柿", 'utf-8')   # 发送者

message['To'] =  Header("测试", 'utf-8')        # 接收者

subject = 'Python SMTP 邮件测试'

message['Subject'] = Header(subject, 'utf-8')

    smtpObj = smtplib.SMTP('localhost')

    smtpObj.sendmail(sender, receivers, message.as_string())

except smtplib.SMTPException:

    print "Error: 无法发送邮件"


3. Operation execl

1. Related formula: Vlookup

vlookup is almost the most commonly used formula in Excel, and is generally used for related queries between two tables. So I first divided this table into two tables.

df1["订单明细号"].duplicated().value_counts()

df2["订单明细号"].duplicated().value_counts()

df_c=pd.merge(df1,df2,on="订单明细号",how="left")


2. Pivot table

Requirement: I want to know the total profit and average profit earned by salespersons in each region.

pd.pivot_table(sale,index="地区名称",columns="业务员名称",values="利润",aggfunc=[np.sum,np.mean])


3. Compare the difference between two columns

Requirement: Compare the difference between the order detail number and order detail number 2 and display it.

sale["订单明细号2"]=sale["订单明细号"]

sale["订单明细号2"][1:10]=sale["订单明细号2"][1:10]+1

result=sale.loc[sale["订单明细号"].isin(sale["订单明细号2"])==False]


4. Remove duplicate values

Requirement: Remove duplicate values ​​of salesperson codes

sale.drop_duplicates("业务员编码",inplace=True)


5. Missing value processing

sale["客户名称"]=sale["客户名称"].fillna(0)

sale.dropna(subset=["客户编码"])


6. Multi-condition filtering

Demand: I want to know the information about salesperson Zhang Ai, who sells goods in the Beijing area with an order amount greater than 6,000.

sale.loc[(sale["地区名称"]=="北京")&(sale["业务员名称"]=="张爱")&(sale["订单金额"]>5000)]


7. Fuzzy filtering of data

Requirement: Filter information whose inventory name contains "Samsung" or "Sony".

sale.loc[sale["存货名称"].str.contains("三星|索尼")]


8. Classification and summary

Demand: The total profit of each salesperson in the Beijing area.

sale.groupby(["地区名称","业务员名称"])["利润"].sum()


9. Conditional calculation

Demand: How many orders have the inventory name containing "Samsung" and a tax higher than 1,000? What is the sum and average profit of these orders? (or minimum value, maximum value, quartile, label difference)

sale.loc[sale["存货名称"].str.contains("三星")&(sale["税费"]>=1000)][["订单明细号","利润"]].describe()


10. Remove spaces between data

Requirement: Remove the spaces on both sides of the inventory name.

sale["存货名称"].map(lambda s :s.strip(""))


4. Drawing analysis

League of Legends defense:

The hero with the lowest defense ability (level 1): Night Hunter, Magic Cat, All Flowers Psychic The hero with the highest defense ability (level 10): Colossus of Justice, Armored Dragon Turtle

img

Annie and Kalma ability matrix:

img

Code example:

from pyecharts.charts import Pie

from pyecharts import options as opts

from pyecharts.charts import Radar

    from pyecharts.charts import Radar

    # //由于雷达图传入的数据得为多维数据,所以这里需要做一下处理

    radar_data = [[10, 10, 10, 10, 10]]

    radar_data1 = [[2, 10, 3, 6, 3]]

    radar_data2 = [[1, 8, 7, 5, 8]]

    # //设置column的最大值,为了雷达图更为直观,这里的月份最大值设置有所不同

        ("物理", 100), ("魔法", 10), ("防御", 10),("难度", 10),("喜好", 10)

    radar.add_schema(schema)

    radar.add("满分", radar_data)

    # //一般默认为同一种颜色,这里为了便于区分,需要设置item的颜色

    radar.add("安妮", radar_data1, color="#E37911")

    radar.add("卡尔玛", radar_data2, color="#1C86EE")

if __name__ == '__main__':


5. Parse word (docx, doc)

Dependency packages:

        if 'docx' in file:

            f = docx.Document(file)

            for para in f.paragraphs:

                res = res + '\n' +para.text

            # 先转格式doc>docx

            os.system("textutil -convert docx '%s'"%file)

            word_reader(file+'x')

            f = docx.Document(file+'x')

            for para in f.paragraphs:

                res = res + '\n' +para.text

        # print(file, 'read failed')


6. Calculator

The math module provides access to the underlying function library for floating point operations:

>>> math.cos(math.pi / 4)


Recommended learning resources

In addition to the above sharing, if you also like programming and want to get a higher salary by learning Python, here is a Python learning material to share with you.

-END-


1. Introduction to Python

The following content is the basic knowledge necessary for all application directions of Python. If you want to do crawlers, data analysis or artificial intelligence, you must first learn them. Anything high-end is built on a primitive foundation. By laying a good foundation, the road ahead will be more stable.All information is available for free at the end of the article!!!

Include:

Computer Basics

Insert image description here

python basics

Insert image description here

Python introductory video episode 600:

Watch zero-based learning videos. Watching videos is the fastest and most effective way to learn. It is easy to get started by following the teacher's ideas in the video, from basic to in-depth.

2. Python crawler

As a popular direction, crawlers are a good choice whether you use them part-time or as an auxiliary skill to improve work efficiency.

Through crawler technology, relevant content can be collected, analyzed and selected to get the information we really need.

This information collection, analysis and integration work can be applied to a very wide range of areas. Whether it is life services, travel, financial investment, product market demand of various manufacturing industries, etc., crawler technology can be used to obtain more accurate and effective information. use.

Insert image description here

Python crawler video information

Insert image description here

3. Data analysis

The "Digital Transformation of China's Economy: Talent and Employment" report released by Tsinghua University School of Economics and Management shows that the data analysis talent gap is expected to reach 2.3 million in 2025.

With such a huge talent gap, data analysis is like a vast blue ocean! Starting salary of 10K is really commonplace.

Insert image description here

4. Database and ETL data warehouse

Enterprises need to regularly transfer cold data from the business database and store it in a warehouse dedicated to storing historical data. Each department can provide unified data services based on its own business characteristics. This warehouse is a data warehouse.

The traditional data warehouse integrated processing architecture is ETL. Using the capabilities of the ETL platform, E = extract data from the source database, L = clean the data (data that does not comply with the rules) and transform the table (perform different dimensions and granularity on the table according to business needs) degree, different business rules calculation and statistics), T=load the processed table to the data warehouse in increments, full quantities, and different times.

Insert image description here

5. Machine Learning

Machine learning is to learn from a part of the computer data, and then predict and judge other data.

The core of machine learning is "using algorithms to parse data, learn from it, and then make decisions or predictions about new data." That is to say, the computer uses the data obtained to derive a certain model, and then uses this model to make predictions. This process is somewhat similar to the human learning process. For example, after a person acquires certain experience, he or she can predict new problems.

Insert image description here

Machine learning materials:

Insert image description here

6. Advanced Python

From basic syntax content to many in-depth advanced knowledge points and understanding of programming language design, after studying here, you will basically understand all the knowledge points from entry to advanced python.

Insert image description here

At this point, you can basically meet the company's employment requirements. If you still don't know where to find interview materials and resume templates, I have compiled one here for you. It can really be said to be a systematic learning route for nannies and caregivers. .

Insert image description here
But learning programming does not happen overnight, but requires long-term persistence and training. In organizing this learning route, I hope to make progress together with everyone, and I can also review some technical points myself. Whether you are a newbie in programming or an experienced programmer who needs to advance, I believe everyone can gain something from it.

It doesn’t happen overnight, but requires long-term persistence and training. In organizing this learning route, I hope to make progress together with everyone, and I can also review some technical points myself. Whether you are a newbie in programming or an experienced programmer who needs to advance, I believe everyone can gain something from it.

Data collection

This complete version of Python learning materials has been uploaded to CSDN official. If you need it, you can click on the CSDN official certification WeChat card below to get it for free↓↓↓< a i=2>【Guaranteed 100% Free】

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_49892805/article/details/134766202