博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
11个实用但你可能不知道的Python程序库
阅读量:2396 次
发布时间:2019-05-10

本文共 2867 字,大约阅读时间需要 9 分钟。

目前,网上已有成千上万个Python包,但几乎没有人能够全部知道它们。单单上就有超过47000个包列表。

现在,越来越多的数据科学家开始使用Python,虽然他们从,,中获得了不少好处,但我仍想向他们介绍一些年长且非常实用的Python库。在本文中,我将列一些不太知名的库,即使你是经验丰富的Python的开发者,也值得过来一看。

1) 

Dolorean是一个非常酷的日期/时间库。类似JavaScript的moment,拥有非常完善的技术文档。

from delorean import Delorean  EST = "US/Eastern"  d = Delorean(timezone=EST)

2) 

你可能从未听过该库,因为它托管在GoogleCode。prettytable主要用于在终端或浏览器端构建很好的输出。

from prettytable import PrettyTable  table = PrettyTable(["animal", "ferocity"])  table.add_row(["wolverine", 100])  table.add_row(["grizzly", 87])  table.add_row(["Rabbit of Caerbannog", 110])  table.add_row(["cat", -1])  table.add_row(["platypus", 23])  table.add_row(["dolphin", 63])  table.add_row(["albatross", 44])  table.sort_key("ferocity")  table.reversesort = True  +----------------------+----------+  |        animal        | ferocity |  +----------------------+----------+  | Rabbit of Caerbannog |   110    |  |      wolverine       |   100    |  |       grizzly        |    87    |  |       dolphin        |    63    |  |      albatross       |    44    |  |       platypus       |    23    |  |         cat          |    -1    |  +----------------------+----------+

3.

好吧,我也是首次安装该库。这是一款非常瘦小的语言转换库,支持15种语言。

from snowballstemmer import EnglishStemmer, SpanishStemmer  EnglishStemmer().stemWord("Gregory")  # Gregori  SpanishStemmer().stemWord("amarillo")  # amarill

4.

你是否还记得,每一次都会因为某个目的而编写网络爬虫工具,以后再也不用了,因为wget就足够你使用了。wget是Python版的网络爬虫库,简单好用。

import wget  wget.download("http://www.cnn.com/")  # 100% [............................................................................] 280385 / 280385

备注:linux和osx用户这样用:from

sh import wget。但是,wget模块还有一个更好的argument handline。

5.

scikit-learn似乎是所有人的宠儿,但在我看来,PyMC更有魅力。PyMC主要用来做Bayesian分析。

from pymc.examples import disaster_model  from pymc import MCMC  M = MCMC(disaster_model)  M.sample(iter=10000, burn=1000, thin=10)  [-----------------100%-----------------] 10000 of 10000 complete in 1.4 sec

6.

sh库用来将shell命令作为函数导入到Python中。在bash中使用是非常实用的,但是在Python中不容易记住怎么使用(即递归搜索文件)。

from sh import find  find("/tmp")  /tmp/foo  /tmp/foo/file1.json  /tmp/foo/file2.json  /tmp/foo/file3.json  /tmp/foo/bar/file3.json

7.

Fuzzywuzzy是一个可以对字符串进行模糊匹配的库,大家有空可以去。

from fuzzywuzzy import fuzz  fuzz.ratio("Hit me with your best shot", "Hit me with your pet shark")  # 85

8.

progressbar是一个进度条库,该库提供了一个文本模式的progressbar。

from progressbar import ProgressBar  import time  pbar = ProgressBar(maxval=10)  for i in range(1, 11):      pbar.update(i)      time.sleep(1)  pbar.finish()  # 60% |########################################################                                      |

9.

colorama主要用来给文本添加各种颜色,并且非常简单易用。

10.

uuid是基于Python实现的UUID库,它实现了UUID标注的1,3,4和5版本,在确保唯一性上真的非常方便。

import uuid  print uuid.uuid4()  # e7bafa3d-274e-4b0a-b9cc-d898957b4b61

11.

bashplotlib是一个绘图库,它允许你使用stdin绘制柱状图和散点图等。

$ pip install bashplotlib  $ scatter --file data/texas.txt --pch x

英文原文:

转载地址:http://bcfob.baihongyu.com/

你可能感兴趣的文章
rac常用命令
查看>>
convert函数引起的ora-01482错误
查看>>
优化案例--重建索引引发的sql性能问题
查看>>
iptables导致无法远程连接oracle
查看>>
rac开启block change tracking
查看>>
rebuild online索引遇到ora-1450
查看>>
针对enq: KO - fast object checkpoint的优化
查看>>
linux下设置发送含中文字符邮件的crontab
查看>>
set autotrace traceonly无法使用
查看>>
rebuild online被终止后的错误 ora-08104
查看>>
重建物理备库案例两则
查看>>
linux下批量修改文件中的字符
查看>>
使用autoexpect避免sftp输入密码
查看>>
监控server磁盘使用率的job
查看>>
mysql导出某个表的部分数据
查看>>
11g 等频直方图下sql不走索引扫描
查看>>
诊断ORA-12519 TNS:no appropriate service handler found
查看>>
lob字段的ora-1555处理方案
查看>>
resize datafile以节省磁盘空间
查看>>
db_file_name_convert设置出错导致备库无法recovery
查看>>