In order to improve efficiency, we often use some Python efficiency tools in our daily work. As an older programming language, Python can realize various automations of daily work.
Pandas is a powerful tool set for analyzing structured data; its basis is Numpy (provided High-performance matrix operations); used for data mining and data analysis, and also provides data cleaning functions.
# 1、安装包 $ pip install pandas # 2、进入python的交互式界面 $ python -i # 3、使用Pandas>>> import pandas as pd>>> df = pd.DataFrame() >>> print(df) # 4、输出结果 Empty DataFrame Columns: [] Index: []
Selenium is a tool for web application testing that can test applications from the perspective of end users. Browser incompatibilities are easier to spot by running tests in different browsers. And it works across many browsers.
You can do a simple test by opening the browser and visiting Google's homepage:
from selenium import webdriver import time browser = webdriver.Chrome(executable_path ="C:Program Files (x86)GoogleChromechromedriver.exe") website_URL ="https://www.google.co.in/" brower.get(website_URL) refreshrate = int(3) #每3秒刷新一次Google主页。 # 它会一直运行,直到你停掉编译器。 while True: time.sleep(refreshrate) browser.refresh()
Flask is a lightweight customizable framework written in Python language. It is more flexible, lightweight, safe and easy to use than other frameworks of the same type. Flask is a very popular web framework currently. Developers can use the Python language to quickly implement a website or web service.
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!'
Scrapy can provide you with powerful support, allowing you to accurately crawl information from the website. It is very practical.
#Now basically most developers will use crawler tools to automate crawling work. So you can use Scrapy when writing crawler coding.
Starting Scrapy Shell is also very simple:
scrapy shell
We can try to extract the value of the search button on the Baidu homepage. First, we must find the class used by the button. An inspect element shows that the class is " bt1".
Specifically perform the following operations:
response = fetch("https://baidu.com") response.css(".bt1::text").extract_first() ==> "Search"
Requests is a powerful HTTP library. With it you can send requests easily. No need to manually add query strings to URLs. In addition, there are many functions, such as authorization processing, JSON/XML parsing, session processing, etc.
Official example:
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) >>> r.status_code 200 >>> r.headers['content-type'] 'application/json; charset=utf8' >>> r.encoding 'utf-8' >>> r.text '{"type":"User"...' >>> r.json() {'private_gists': 419, 'total_private_repos': 77, ...}
Faker is a Python package that generates fake data for you data. Whether you need to bootstrap a database, create good-looking XML documents, fill out your persistence to emphasize testing it, or get the same data from a production service, Faker is for you
With it, you can generate fake names, addresses, descriptions, etc. very quickly! The following script is an example. I create a contact entry containing the name, address and some description text:
Installation:
pip install Faker from faker import Faker fake = Faker() fake.name() fake.address() fake.text()
Python image processing tool-Pillow has quite powerful image processing functions. It can be used when you need to do image processing. After all, as a developer, you should choose a more powerful image processing tool.
Simple example:
from PIL import Image, ImageFilter try: original = Image.open("Lenna.png") blurred = original.filter(ImageFilter.BLUR) original.show() blurred.show() blurred.save("blurred.png") except: print "Unable to load image"
Effective tools can help us complete work tasks more quickly, so I will share with you a few tools that I think are useful. , and I hope these 7 Python efficiency tools can help you.
The above is the detailed content of Recommended seven Python efficiency tools!. For more information, please follow other related articles on the PHP Chinese website!