python office automation? Learn enough to use these

A question was raised on almost know: carried out with python office automation needs to learn what knowledge?

This may be confusing a lot of non-IT professionals face, trying to use python work, but do not know how to start?
python increasingly popular in the field of office automation, batch processing is simply the Gospel overtime family.

Office automation is nothing more than excel, ppt, word, e-mail, document processing, data analysis and processing, these reptiles, the reason I came to a point that knowledge management office automation python.

  • python basis
  • excel automation
  • ppt automation
  • word automation
  • Mail processing
  • Batch file
  • Data processing and analysis
  • Automation reptiles

Below 11 Xiangjie.

python basis

Do these on the premise that use Python, at least be familiar with the basic syntax, you can write a small script.

Requirements for python syntax, you can control part of python based tutorial that needs to learn to see, to find free video tutorials follow the science, practice and then knock Code. If the habit of reading, you can buy this python primer for future reference.
| Syntax | main content |
| --- | --- |
| basic data types | immutable data (3): Number (number), String (String), Tuple (tuple)
the variable data (3 ): list (list), Dictionary (dictionary), Set (collection) |
| operator | arithmetic operators, logical operators, assignment operators, comparison operators, bitwise operators ... |
| numeric type | integer (Int), float (float), complex (complex) |
| conditional control statements | if ... elif ... else statement |
| Loops | while statement, for statement |
| function | def defined functions, function calls, parameter passing, anonymous functions ... |
| iteration | iterative process, iterators, generators, generator expressions |
| file operations | open () function, read, readline, readlines, write ... method |
| os module | handling system files and directories |
| module | import module, the module common standards, common third-party libraries |
| errors and exceptions | try / except statement |
| object-oriented | simple object-oriented concepts to grasp |
before finishing python the core part of the basic grammar, for reference only:

 a text read a map python , Reduce function

You get to know one article Python iterators and generators

article to get to know Python anonymous function

a text file read and write Python get to know

a culture to get to know Python loop techniques

 article to get to know Python errors and exceptions

article get to know the date and time of processing python

The syntax is the key, we must understand the basic concepts of programming in python, go to learn other tools library.

Or it will be very painful.

excel automation

In fact, the family office can use VBA to solve automation problems, but many people may not be used.

For python excel there are many third-party libraries can be used, such as xlwings, xlsxwriter, xlrd, xlwt, pandas, xlsxwriter, win32com, xlutils and so on.

These libraries can easily achieve the excel file deletions rewrite, modify the format, of course, does not recommend you all to try, this time the cost is too high. The two pandas and use xlwings enough, basically solve all the problems excel automation.

xlwing can read and write not only excel, but also for format adjustments, VBA operation, very powerful and easy to use.

Written before a xlwings introductory tutorial:

xlwings, let excel fly!

And xlrd, xlwt use:

 to teach you to read and write excel batch file using Python

You can also check xlwings specific usage (Chinese summary):

https://www.jianshu.com/p/e21894fc5501
https://www.jianshu.com/p/b534e0d465f7
https://www.jianshu.com/p/ de7efe591c12

Tell me what the best course is net tutorial:

https://www.xlwings.org/

pandas是大家都熟悉的数据处理利器,它也支持excel的读写,接口友好。这个后面会讲到。

如果你对python自动化处理excel很有兴趣,也可以买一本专门的教材来看。

ppt自动化

python当然是支持ppt的自动化处理,主要的库有pywin32com、pptx,可以创建、修改ppt文件。

推荐使用pptx库,目前主流的ppt处理库。

学习网站:

https://python-pptx.readthedocs.io/en/latest/

word自动化

python操作Word的库:

  • python-docx、import docx:只对windows平台有效
  • pypiwin32、import win32com:跨平台,但无法处理doc格式的word文本,doc格式不是基于xml的
  • textract、import textract:它同时兼顾“doc”和“docx”,但安装过程需要一些依赖。
    你可以批量的用python生成word文件,推荐使用docx,不需要会太多。

学习网站:

https://python-docx.readthedocs.io/en/latest/

邮件处理

python处理邮件也是极其便利的,smtplib、imaplib、email三个库配合使用,实现邮件编写、发送、接收、读取等一系列自动化操作,省时省力。

写过一个发送邮件教程,亲测可用:

干货 | 解放双手,用Python实现自动发送邮件

看了其他很多教程都有各种各样的问题,需要不断改bug,所以这个大家先可以跑跑上面的代码。

文件批量处理

文件处理包括批量修改或创建文件名、批量生成文档、批量修改路径等等重复性操作。如果一个个手工操作,那真的心累。

python在处理批量操作有得天独厚的优势,成千上万的文件修改可能只需几秒的时间。

os是python文件操作的库,可以实现对电脑上文件的增删改查。

学习网站:

https://www.runoob.com/python3/python3-os-file-methods.html

https://www.liaoxuefeng.com/wiki/1016959663602400/1017606916795776

方法 作用
os.chdir(path) 改变当前工作目录
os.getcwd() 返回当前工作目录
os.listdir() 返回path指定的文件夹包含的文件或文件夹的名字的列表
os.makedirs(path[, mode]) 创建一个名为path的文件夹
os.remove(path) 删除路径为path的文件
... ...

数据处理和分析

我就是做数据分析工作的,基本也是python作为主要工具,所以这一块毋庸置疑是python自动化办公最有价值的部分。

数据处理的库主要有:pandas、numpy、matplotlib、sklearn...

pandas是一款不断进步的python数据科学库,它的数据结构十分适合做数据处理,并且pandas纳入了大量分析函数方法,以及常用统计学模型、可视化处理。

如果你使用python做数据分析,在数据预处理的过程,几乎九成的工作需要使用pandas完成。

在一些企业招分析师的笔试题中,pandas已经作为必考的工具,所以如果你想要入行数据分析师,请努力学习使用pandas。

numpy是python的数值计算库,包括pandas之类的很多分析库都建立在numpy基础上。

numpy的核心功能包括:

  • ndarray,一个具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组
  • 用于对整组数据进行快速运算的标准数学函数(无需编写循环)
  • 用于读写磁盘数据的工具以及用于操作内存映射文件的工具
  • 线性代数、随机数生成以及傅里叶变换功能
  • 用于集成由C、C++、Fortran等语言编写的代码的A C API

numpy之于数值计算特别重要是因为它可以高效处理大数组的数据。这是因为:

  • 比起Python的内置序列,numpy数组使用的内存更少
  • numpy可以在整个数组上执行复杂的计算,而不需要Python的for循环

matplotlib和seaborn是python主要的可视化工具,建议大家都去学学,数据的展现和数据分析同样重要。

sklearn和keras,sklearn是python机器学库,涵盖了大部分机器学习模型。keras是深度学习库,它包含高效的数值库Theano和TensorFlow。

这些是大家耳熟能详的神库,非常推荐去学习。

之前写过很多关于python数据分析处理的回答和文章,这里不再啰嗦了。

好看不火 | 怎么才有数据分析思路?

如何系统地学习Python 中 matplotlib, numpy, scipy, pandas?

小白入门Python数据科学全教程

自动化爬虫

相信爬虫是大家最感兴趣的,python爬虫有很多的实现库,比如:urllib、requests、scrapy等,以及xpath、beautifulsoup等解析库。

爬虫入门容易,但学精难,所以初学者可以尝试写点简单的爬虫,比如豆瓣、知乎、微博呀。

案例都给你准备好了:

小白如何入门Python爬虫

使用requests爬取拉勾网python职位数据

实操 | 从0到1教你用Python来爬取整站天气网

推荐大家去学习requests、bs4来入门爬虫,提供对应中文学习网站:

https://2.python-requests.org//zh_CN/latest/

https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/

其它

其它不常用的自动化办公库,像处理pdf、图片、视音频等,这里不做过多介绍。

如果有兴趣可以在本文末留言,你用过哪些逆天的python库,解决了哪些问题?

Guess you like

Origin www.cnblogs.com/zhuwjwh/p/12325688.html