Too fragrant! 5 more Python libraries that will make you meet each other late!

Python is a simple language with many libraries. No matter what your needs, it has a function to meet your needs. Although I have been learning Python for many years, I can always find some low-key but very useful and interesting libraries.

Today I will share with you some of the function libraries that we have met and hate late. If you have more fun and useful ones, please share them.

1 、 myqr

myqr is a tool library for making cool QR codes. Just a few lines of code can make you look amazing.

installation

pip install myqr

Insert picture description here

Code

from MyQR import myqr
import os
 
version, level, qr_name = myqr.run(
    words="https://www.baidu.com",          # 可以是字符串,也可以是网址(前面要加http(s)://)
    version=1,                              # 设置容错率为最高
    level='H',                              # 控制纠错水平,范围是L、M、Q、H,从左到右依次升高
    picture="1.gif",                           # 将二维码和图片合成
    colorized=True,                         # 彩色二维码
    contrast=1.0,                           #用以调节图片的对比度,1.0 表示原始图片,更小的值表示更低对比度,更大反之。默认为1.0
    brightness=1.0,                         #用来调节图片的亮度,其余用法和取值同上
    save_name="2.gif",                     # 保存文件的名字,格式可以是jpg,png,bmp,gif
    save_dir=os.getcwd()                    #控制位置
)

Let's see the effect
Insert picture description here

2 、 Tqdm

Tqdm displays a library of looping progress bars. It can add a progress prompt message in the long loop to facilitate real-time viewing of the running progress. Users only need to encapsulate any iterator. It is a fast and extensible progress bar tool library.

installation

pip install tqdm

Example

from tqdm import tqdm
import time

for i in tqdm(range(100)):
    time.sleep(0.1)

3、Pendulum

For those who feel frustrated when dealing with date and time in Python, Pendulum is definitely a boon. It is a Python package that simplifies date and time operations. This is the lowest-key but very powerful time processing library that has been seen so far.

Official document: https://pypi.org/project/pendulum/

installation

pip install pendulum

Example

import pendulum

# 1、获取时间
print(pendulum.now())
print(pendulum.today())
print(pendulum.tomorrow())
print(pendulum.yesterday())

# 2、转字符串
print(pendulum.now().to_datetime_string())
# 2019-12-12 15:51:22

print(pendulum.now().to_date_string())
# 2019-12-12

print(pendulum.now().to_time_string())
# 22:25:05

print(pendulum.now().format('%Y-%m-%d'))

# 3、类型测试
from datetime import datetime
dt =pendulum.datetime(2015, 2, 5)
print(isinstance(dt, datetime))
True


# 4、解析规范的时间
print(pendulum.from_format('2019-12-12', '%Y-%m-%d'))
# 2019-12-12T00:00:00+00:00

print(pendulum.parse('2019-12-12'))
# 2019-12-12T00:00:00+00:00


# 6、属性
now = pendulum.now()
print(now.year)
print(now.month)
print(now.day)
print(now.hour)
print(now.minute)
print(now.second)

# 7、时间加减
now = pendulum.now()
print(now)
print(now.add(years=1))
print(now.subtract(years=1))

# 时间跨度计算
print(now.diff(now.add(years=1)).in_years())


# 8、设置语言地区
pendulum.set_locale('zh')

print(pendulum.now().subtract(days=1).diff_for_humans())
# 1天前

print(pendulum.now().subtract(hours=1).diff_for_humans())
# 1小时前

# 9、生成时间序列
period = pendulum.period(pendulum.now(), pendulum.now().add(days=3))

# years, months, weeks, days, hours, minutes and seconds
for dt in period.range('days'):
    print(dt)

4、Fuzzywuzzy

The name of this library sounds strange, but fuzzywuzzy is a very useful library in terms of string matching. Operations such as calculating string matching degree and token matching degree can be easily implemented, and records stored in different databases can also be easily matched.

installation

pip install fuzzywuzzy

Example

from fuzzywuzzy import fuzz
from fuzzywuzzy import process
# 简单匹配度
fuzz.ratio("this is a test", "this is a test!")

# 模糊匹配度
fuzz.partial_ratio("this is a test", "this is a test!")

5、Bokeh

Bokeh is a cool interactive visualization library serving the browser. It provides the elegant and concise structure of general graphics, and provides high-performance interactivity on large or streaming data sets . Bokeh can help anyone who wants quick and easy interactive drawing, dashboard and data applications.

from bokeh.plotting import figure, output_file, show
# 创建图表
p = figure(plot_width=300, plot_height=300, tools="pan,reset,save")
# 图表中添加圆
p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3,alpha=0.5)
# 定义输出形式
output_file("foo.html")
# 展示图表
show(p)

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-gUO1VZq6-1599980275072)(https://imgkr2.cn-bj.ufileos.com/5da66ff3-f752-42d9 -ab7c-642c4a57b418.png?UCloudPublicKey=TOKEN_8d8b72be-579a-4e83-bfd0-5f6ce1546f13&Signature=foV%252F3Ke97v2oehUDDZCOc%252BYB0i0%253D&Expires=1599473489)]

Data sharing

I recommend a book "Advanced Python" that is interested in Python. It is a Chinese translation of "Intermediate Python". This book has the following advantages: simple, easy to read, and easy to translate. These are not the main points, the main point is: it is a book that opens up the mind. Whether you are a Python beginner or a Python expert, it will always show you the best things in Python.

method of obtaining:

Original link: Too fragrant! 5 more Python libraries that will make you meet each other late!

Reply to keywords in the background of the original link above: Python advanced

Recommended reading

For more exciting content, follow the WeChat public account "Python learning and data mining"

In order to facilitate technical exchanges, this account has opened a technical exchange group. If you have any questions, please add a small assistant WeChat account: connect_we. Remarks: The group is from CSDN, welcome to reprint, favorites, codewords are not easy, like the article, just like it! Thanks
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_38037405/article/details/108562583