<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          真香!推薦6個冷門Python數(shù)據(jù)分析工具

          共 3619字,需瀏覽 8分鐘

           ·

          2022-02-12 22:21

          大家好,歡迎來到 Crossin的編程教室 !

          用Python處理數(shù)據(jù)大家都不陌生了,屬于常規(guī)操作,但常規(guī)之下也還是暗藏技巧的,本篇就來分享6個好玩高效的操作,幫助大家提高效率。

          一、Pandas Profiling

          Pandas Profiling提供數(shù)據(jù)的一個整體報告,是一個幫助我們理解數(shù)據(jù)的過程。它可以簡單快速地對Pandas的數(shù)據(jù)框數(shù)據(jù)進行探索性數(shù)據(jù)分析。

          其實,Pandasdf.describe()df.info()函數(shù)也可以實現(xiàn)數(shù)據(jù)探索過程第一步。但它們只提供了對數(shù)據(jù)非?;镜母攀?。而Pandas中的Profiling功能簡單通過一行代碼就能顯示大量信息,同時還能生成交互式HTML報告。

          對于給定的數(shù)據(jù)集,Pandas中的profiling包計算了以下統(tǒng)計信息:

          Pandas Profiling包計算出的統(tǒng)計信息包括直方圖、眾數(shù)、相關(guān)系數(shù)、分位數(shù)、描述統(tǒng)計量、其他信息包括類型、單一變量值、缺失值等。

          安裝

          pipconda即可,使用方法很簡單,如下:

          import?pandas?as?pd
          import?pandas_profiling
          df?=?pd.read_csv('titanic/train.csv')
          pandas_profiling.ProfileReport(df)

          用法

          以titanic數(shù)據(jù)集來演示profiling的功能。

          import?pandas?as?pd
          import?pandas_profiling
          df?=?pd.read_csv('titanic/train.csv')
          pandas_profiling.ProfileReport(df)?

          除了導(dǎo)入庫之外只需要一行代碼,就能顯示數(shù)據(jù)報告的詳細(xì)信息,包括必要的圖表。

          還可以使用以下代碼將報告導(dǎo)出到交互式HTML文件中。

          profile?=?pandas_profiling.ProfileReport(df)
          profile.to_file(outputfile="Titanic?data?profiling.html")


          二、pretty print

          pprint是Python中的內(nèi)置模塊。它能夠以格式清晰,可讀性強漂亮格式打印任意數(shù)據(jù)結(jié)構(gòu)。一個例子對比下printpprint。

          #?定義個字典,測試用
          my_dict?=?{'Student_ID':?34,'Student_name'?:?'Tom',?'Student_class'?:?5,
          ??????????'Student_marks'?:?{'maths'?:?92,
          ????????????????????????????'science'?:?95,
          ????????????????????????????'social_science'?:?65,
          ????????????????????????????'English'?:?88}
          ??????????}

          print

          #?正常的print
          print(my_dict)
          #?輸出結(jié)果如下:
          {'Student_ID':?34,?'Student_name':?'Tom',?'Student_class':?5,?'Student_marks':?{'maths':?92,?'science':?95,?'social_science':?65,?'English':?88}}

          pprint

          #?使用pprint輸出
          import?pprint
          pprint.pprint(my_dict)
          #?輸出結(jié)果如下:
          {'Student_ID':?34,
          ?'Student_class':?5,
          ?'Student_marks':?{'English':?88,
          ???????????????????'maths':?92,
          ???????????????????'science':?95,
          ???????????????????'social_science':?65},
          ?'Student_name':?'Tom'}

          可以清楚看到pprint的優(yōu)勢之處,數(shù)據(jù)結(jié)構(gòu)一目了然啊。

          三、Python Debugger

          交互式調(diào)試器也是一個神奇的函數(shù),如果在運行代碼單元格時出現(xiàn)報錯,可以在新行中鍵入%debug運行它。這將打開一個交互式調(diào)試環(huán)境,自動轉(zhuǎn)到報錯發(fā)生的位置,并且還可以檢查程序中分配的變量值并執(zhí)行操作。要退出調(diào)試器,按q。比如下面這個例子。

          x?=?[1,2,3]
          y?=?2
          z?=?5

          result?=?y+z
          print(result)
          result2?=?x+y
          print(result2)

          大家應(yīng)該能看出x+y肯定會報錯,因為二者不是一個類型,無法進行運算操作。然后我們敲入%debug

          %debug

          這時會出現(xiàn)對話框讓我們互交式輸入命令,比如我們可以像下面這樣做。

          四、Cufflinks

          這個庫之前也介紹過,對于數(shù)據(jù)探索的可視化分析超級好用,低代碼量便可生成漂亮的可視化圖形。下面舉一個例子:

          cufflinksplotly的基礎(chǔ)上做了一進一步的包裝,方法統(tǒng)一,參數(shù)配置簡單。其次它還可以結(jié)合pandasdataframe隨意靈活地畫圖??梢园阉稳轂?/span>"pandas like visualization"。

          比如下面的lins線圖。

          import?pandas?as?pd
          import?cufflinks?as?cf
          import?numpy?as?np

          cf.set_config_file(offline=True)
          cf.datagen.lines(1,500).ta_plot(study='sma',periods=[13,21,55])

          再比如box箱型圖

          cf.datagen.box(20).iplot(kind='box',legend=False)

          看著這動態(tài)圖就愛不釋手啊,有木有!

          五、Pyforest

          這是一個能讓你偷懶的import神器,可以提前在配置文件里寫好要導(dǎo)入的三方庫,這樣每次編輯腳本的時候就省去了開頭的一大堆import 各種庫,對于有常用和固定使用庫的朋友來說無疑也是提高效率的工具之一。

          pyforest支持大部分流行的數(shù)據(jù)科學(xué)庫,比如pandas,numpy,matplotlibseaborn,sklearntensorflow等等,以及常用的輔助庫如os,sys,re,pickle等。

          此用法對于自己頻繁調(diào)試很方便,但對于那些頻繁跨環(huán)境比如和其它人共享腳本調(diào)試的時候就不是很好用了,因為別人不一定使用它。

          看下面這個操作就明白了:

          六、Jupyter notebook的筆記高亮

          此方法僅適用于Jupyter notebook中,當(dāng)我們想高亮筆記,讓筆記變得美觀的時候,這個方法非常的香。

          筆記的高亮的顏色根據(jù)不同情況分為幾種,前端的同學(xué)一看就明白,區(qū)別就是每種顏色代碼的class類型不一樣,其它只要在div標(biāo)簽中寫內(nèi)容就好。下面看下用法。

          藍色代表info

          <div?class="alert?alert-block?alert-info">
          <b>Tip:b>?Use?blue?boxes?(alert-info)?for?tips?and?notes.?
          If?it’s?a?note,?you?don’t?have?to?include?the?word?“Note”.
          div>

          黃色代表warning

          <div?class="alert?alert-block?alert-warning">
          <b>Example:b>?Yellow?Boxes?are?generally?used?to?include?additional?examples?or?mathematical?formulas.
          div>

          綠色代表success

          <div?class="alert?alert-block?alert-success">
          Use?green?box?only?when?necessary?like?to?display?links?to?related?content.
          div>

          紅色代表danger

          <div?class="alert?alert-block?alert-danger">
          It?is?good?to?avoid?red?boxes?but?can?be?used?to?alert?users?to?not?delete?some?important?part?of?code?etc.?
          div>

          這里有個小提示:如果你直接復(fù)制到jupyter notebook中可能會報錯,因為默認(rèn)是代碼的格式,所以你需要選中單元格按Esc變成可切換模式,然后再按Y切換成文本模式。這時候再運行shift+ok就ok了。看下面這個例子。

          以上就是6個冷門但卻實用的數(shù)據(jù)分析庫。

          如果文章對你有幫助,歡迎轉(zhuǎn)發(fā)/點贊/收藏~


          作者:wLsq

          來源:Python數(shù)據(jù)科學(xué)


          _往期文章推薦_

          安利一個提升python數(shù)據(jù)分析效率的神器




          如需了解付費精品課程教學(xué)答疑服務(wù)
          請在Crossin的編程教室內(nèi)回復(fù): 666

          瀏覽 63
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲色无码专区观看在线观 | 欧美黄片一级 | 无码福利导航 | 无码中文日韩 | 久久依人日 |