您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > 11个你可能不知道的Python库
11个你可能不知道的Python库(中文)阅读目录1)delorean2)prettytable3)snowballstemmer4)wget5)PyMC6)sh7)fuzzywuzzy8)progressbar9)colorama10)uuid11)bashplotlib1)delorean非常酷的日期/时间库123fromdeloreanimportDeloreanEST=US/Easternd=Delorean(timezone=EST)2)prettytable可以在浏览器或终端构建很不错的输出12345678910111213141516171819202122fromprettytableimportPrettyTabletable=PrettyTable([animal,ferocity])table.add_row([wolverine,100])table.add_row([grizzly,87])table.add_row([RabbitofCaerbannog,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|+----------------------+----------+|RabbitofCaerbannog|110||wolverine|100||grizzly|87||dolphin|63||albatross|44||platypus|23||cat|-1|+----------------------+----------+3)snowballstemmer非常瘦小的语言转换库,支持15种语言12345fromsnowballstemmerimportEnglishStemmer,SpanishStemmerEnglishStemmer().stemWord(Gregory)#GregoriSpanishStemmer().stemWord(amarillo)#amarill4)wgetPython的网络爬虫库123importwgetwget.download(#100%[............................................................................]280385/2803855)PyMCPyMC,一个用于贝叶斯分析的函数库12345frompymc.examplesimportdisaster_modelfrompymcimportMCMCM=MCMC(disaster_model)M.sample(iter=10000,burn=1000,thin=10)[-----------------100%-----------------]10000of10000completein1.4sec6)sh将shell命令作为函数导入Python脚本1234567fromshimportfindfind(/tmp)/tmp/foo/tmp/foo/file1.json/tmp/foo/file2.json/tmp/foo/file3.json/tmp/foo/bar/file3.json7)fuzzywuzzy用于字符串匹配率、令牌匹配等123fromfuzzywuzzyimportfuzzfuzz.ratio(Hitmewithyourbestshot,Hitmewithyourpetshark)#858)progressbar如其名,一个滚动条函数库1fromprogressbarimportProgressBar2345678importtimepbar=ProgressBar(maxval=10)foriinrange(1,11):pbar.update(i)time.sleep(1)pbar.finish()#60%|########################################################|9)colorama一个色彩库,可以为文本添加丰富的色彩10)uuid一个可以产生唯一uuid的库123importuuidprintuuid.uuid4()#e7bafa3d-274e-4b0a-b9cc-d898957b4b6111)bashplotlibPython的绘图控件,可以绘制直方图、散点图等12$pipinstallbashplotlib$scatter--filedata/texas.txt--pchx(原文)TherearetonsofPythonpackagesoutthere.Somanythatnoonemanorwomancouldpossiblycatchthemall.PyPialonehasover47,000packageslisted!Recently,withsomanydatascientistsmakingtheswitchtoPython,Icouldn'thelpbutthinkthatwhilethey'regettingsomeofthegreatbenefitsofpandas,scikit-learn,andnumpy,they'remissingoutonsomeolderyetequallyhelpfulPythonlibraries.Inthispost,I'mgoingtohighlightsomelesser-knownlibraries.EvenyouexperiencedPythonistasshouldtakealook,theremightbeoneortwointhereyou'veneverseen!1)deloreanDeloreanisareallycooldate/timelibrary.Apartfromhavingasweetname,it'soneofthemorenaturalfeelingdate/timemunginglibrariesI'veusedinPython.It'ssortoflikemomentinjavascript,exceptIlaugheverytimeIimportit.Thedocsarealsogoodandinadditiontobeingtechnicallyhelpful,theyalsomakecountlessBacktotheFuturereferences.fromdeloreanimportDeloreanEST=US/Easternd=Delorean(timezone=EST)2)prettytableThere'sachanceyouhaven'theardofprettytablebecauseit'slistedonGoogleCode,whichisbasicallythecodingequivalentofSiberia.Despitebeingexiledtoacold,snowyanddesolateplace,prettytableisgreatforconstructingoutputthatlooksgoodintheterminalorinthebrowser.Soifyou'reworkingonanewplug-infortheIPythonNotebook,checkoutprettytableforyourHTML__repr__.fromprettytableimportPrettyTabletable=PrettyTable([animal,ferocity])table.add_row([wolverine,100])table.add_row([grizzly,87])table.add_row([RabbitofCaerbannog,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|+----------------------+----------+|RabbitofCaerbannog|110||wolverine|100||grizzly|87||dolphin|63||albatross|44||platypus|23||cat|-1|+----------------------+----------+3)snowballstemmerOksothefirsttimeIinstalledsnowballstemmer,itwasbecauseIthoughtthenamewascool.Butit'sactuallyaprettyslicklittlelibrary.snowballstemmerwillstemwordsin15differentlanguagesandalsocomeswithaporterstemmertoboot.fromsnowballstemmerimportEnglishStemmer,SpanishStemmerEnglishStemmer().stemWord(Gregory)#GregoriSpanishStemmer().stemWord(amarillo)#amarill4)wgetRemembereverytimeyouwrotethatwebcrawlerforsomespecificpurpose?Turnsoutsomebodybuiltit...andit'scalledwget.Recursivelydownloadawebsite?Grabeveryimagefromapage?Sidestepcookietraces?Done,done,anddone.MovieMarkZuckerbergevensaysithimselfFirstupisKirkland,theykeepeverythingopenandallowindexesontheirapacheconfiguration,soalittlewgetmagicisenoughtodownloadtheentireKirklandfacebook.Kidstuff!ThePythonversioncomeswithjustabouteveryfeatureyoucouldaskforandiseasytouse.importwgetwget.download()#100%[............................................................................]280385/280385Notethatanotheroptionforlinuxandosxuserswouldbetousedo:fromshimportwget.HoweverthePythonwgetmoduledoeshaveabetterargumenthandline.5)PyMCI'mnotsurehowPyMCgetsleftoutofthemixsooften.scikit-learnseemstobeeveryone'sdarling(
本文标题:11个你可能不知道的Python库
链接地址:https://www.777doc.com/doc-3058451 .html