安利几个非常实用的 Python 库
i小码哥
共 4175字,需浏览 9分钟
·
2020-10-18 04:14
原文地址:https://dwz.cn/FBj1Ktxv
译文链接:https://dwz.cn/moEU7xzr
1.Wget
$ pip install wget
import wget
url = 'http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3'
filename = wget.download(url)
100% [................................................] 3841532 / 3841532
filename
'razorback.mp3'
### Pendulum
$ pip install pendulum
import pendulum
dt_toronto = pendulum.datetime(2012, 1, 1, tz='America/Toronto')
dt_vancouver = pendulum.datetime(2012, 1, 1, tz='America/Vancouver')
print(dt_vancouver.diff(dt_toronto).in_hours())
3
3.imbalanced-learn
pip install -U imbalanced-learn
# 或者
conda install -c conda-forge imbalanced-learn
4.FlashText
$ pip install flashtext
from flashtext import KeywordProcessor
keyword_processor = KeywordProcessor()
# keyword_processor.add_keyword(, )
keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('Bay Area')
keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.')
keywords_found
['New York', 'Bay Area']
keyword_processor.add_keyword('New Delhi', 'NCR region')
new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')
new_sentence
'I love New York and NCR region.'
Fuzzywuzzy
$ pip install fuzzywuzzy
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
# 简单匹配度
fuzz.ratio("this is a test", "this is a test!")
97
# 模糊匹配度
fuzz.partial_ratio("this is a test", "this is a test!")
100
6.PyFlux
pip install pyflux
7.Ipyvolume
$ pip install ipyvolume
$ conda install -c conda-forge ipyvolume
动画
体绘制
8.Dash
pip install dash==0.29.0 # 核心 dash 后端
pip install dash-html-components==0.13.2 # HTML 组件
pip install dash-core-components==0.36.0 # 增强组件
pip install dash-table==3.1.3 # 交互式 DataTable 组件(最新!)
9.Gym
pip install gym
CartPole-v0
环境中的一个实例,它的时间步数为 1000,每一步都会渲染整个场景。总结
--------------------- End ---------------------
后台回复关键字:自学,获取一份精心整理的 5本 Python 经典用书 后台回复关键字:国庆,获取50本电子书。 推荐阅读
欢迎大家点赞,留言,转发,转载,感谢大家的相伴与支持。
做知识的传播者,随手转发,小码哥与您同行。
评论