11個可能不知道的Python庫

目前,網上已有成千上萬個Python包,但幾乎沒有人能夠全部知道它們。單單PyPi上就有超過47000個包列表。

現在,越來越多的數據科學家開始使用Python,雖然他們從pandas,scikit-learn,numpy中獲得了不少好處,但我仍想向他們介紹一些年長且非常實用的Python庫。在本文中,我將列一些不太知名的庫,即使你是經驗豐富的Python的開發者,也值得過來一看。

1) delorean

非常酷的日期/時間庫

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

2) 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) snowballstemmer

非常瘦小的語言轉換庫,支持15種語言

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

4) wget

Python的網絡爬蟲庫

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

5) PyMC

PyMC,一個用於貝葉斯分析的函數庫

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腳本

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

如其名,一個滾動條函數庫

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

一個可以產生唯一uuid的庫

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

11) bashplotlib

Python的繪圖控件,可以繪製直方圖、散點圖等

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

這裏寫圖片描述

【注】本文轉自:http://blog.92fenxiang.com/articles/1421855937

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章