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

          高級(jí),這個(gè)Python庫(kù)助力pandas智能可視化分析

          共 3392字,需瀏覽 7分鐘

           ·

          2021-06-15 20:25


          導(dǎo)讀:介紹一個(gè)可視化工具——LUX


          作者:朱衛(wèi)軍
          來(lái)源:Python大數(shù)據(jù)分析(ID:pydatas)




          Pandas是用于數(shù)據(jù)處理的核心庫(kù),它也可以進(jìn)行簡(jiǎn)單的可視化,繪制散點(diǎn)、折線、直方等基礎(chǔ)圖表都不在話下。


          Pandas自帶的可視化方法是基于matplotlib的函數(shù)接口,在Jupyter里可以靜態(tài)展示。

          這次介紹一個(gè)可視化工具——LUX,它能自動(dòng)地將DataFrame數(shù)據(jù)轉(zhuǎn)化為統(tǒng)計(jì)圖表,讓你可以一目了然地看到相關(guān)性、分布、頻率等信息。

          LUX在Jupyter Notebook或Lab中進(jìn)行交互,圖表與數(shù)據(jù)可以同步顯示。

          項(xiàng)目地址: 
          https://github.com/lux-org/lux



          01 使用LUX


          以下面數(shù)據(jù)集(美國(guó)各大學(xué)信息表)為例:

          # 導(dǎo)入pandas和lux庫(kù)
          import pandas as pd
          import lux

          #加載數(shù)據(jù)
          df = pd.read_excel("C:\\Users\\zii\\Documents\\USA_College.xlsx")
          df

          讀取的數(shù)據(jù)如下:


          除了顯示的數(shù)據(jù)表外,同時(shí)你還會(huì)看到數(shù)據(jù)集上面出現(xiàn)一個(gè)按鈕,可以進(jìn)行數(shù)據(jù)/圖表的交換顯示。


          所以說(shuō)只需要導(dǎo)入lux庫(kù),就能直接使用圖表功能。


          LUX顯示有三種類型的圖表,代表的統(tǒng)計(jì)學(xué)含義分別是相關(guān)性、直方分布、事件頻次。


          除了全表的可視化探索外,你還可以研究特定變量間的關(guān)系。

          比如,我想看SAT平均值和收入中位數(shù)的關(guān)聯(lián)性.

          df.intent = ['SAT平均值','收入中位數(shù)']
          df


          左邊的表是兩個(gè)變量的總體分布,右邊是在有篩選條件下的分布。


          02 導(dǎo)出圖表


          LUX支持圖表的導(dǎo)出,既可以導(dǎo)出圖表文件,也可以導(dǎo)出相應(yīng)的matplotlib、altair代碼。

          首先選定一個(gè)或多個(gè)圖表,點(diǎn)擊導(dǎo)出按鈕。


          可以直接將選定的圖表單獨(dú)顯示出來(lái):


          1. 導(dǎo)出htmldf.save_as_html('hpi.html')

          2. 導(dǎo)出matplotlib代碼

          vis = df.exported
          print (vis[0].to_matplotlib())


          3. 導(dǎo)出altair代碼

          vis = df.exported
          print(vis[0].to_Altair())


          導(dǎo)出的代碼可以直接運(yùn)行:

          import altair as alt

          chart = alt.Chart(df).mark_circle().encode(
              x=alt.X('SAT平均值',scale=alt.Scale(domain=(6661534)),type='quantitative', axis=alt.Axis(title='SAT平均值')),
              y=alt.Y('收入中位數(shù)',scale=alt.Scale(domain=(20200125600)),type='quantitative', axis=alt.Axis(title='收入中位數(shù)'))
          )
          chart = chart.configure_mark(tooltip=alt.TooltipContent('encoding')) # Setting tooltip as non-null
          chart = chart.interactive() # Enable Zooming and Panning
          chart = chart.encode(color=alt.Color('最高學(xué)位',type='nominal'))

          chart = chart.configure_title(fontWeight=500,fontSize=13,font='Helvetica Neue')
          chart = chart.configure_axis(titleFontWeight=500,titleFontSize=11,titleFont='Helvetica Neue',
          labelFontWeight=400,labelFontSize=8,labelFont='Helvetica Neue',labelColor='#505050')
          chart = chart.configure_legend(titleFontWeight=500,titleFontSize=10,titleFont='Helvetica Neue',
          labelFontWeight=400,labelFontSize=8,labelFont='Helvetica Neue')
          chart = chart.properties(width=160,height=150)

          chart



          03 安裝設(shè)置


          lux安裝過(guò)程和其他庫(kù)一樣,可以通過(guò)pip或conda安裝,直接在命令行輸入:

          pip install lux-api


          conda install -c conda-forge lux-api

          因?yàn)閘ux一般用在Jupyter生態(tài)中,所以需要安裝并激活luxwidget拓展,才能顯示交互式窗口。

          如果你是在Jupyter Notebook或VSCode中使用,使用下面代碼激活拓展:

          jupyter nbextension install --py luxwidget
          jupyter nbextension enable --py luxwidget

          如果你使用的是Jupyter Lab,則激活lab拓展:

          jupyter labextension install @jupyter-widgets/jupyterlab-manager
          jupyter labextension install luxwidget



          04 總結(jié)


          LUX是一個(gè)不錯(cuò)的數(shù)據(jù)可視化分析工具,能智能地輔助Pandas做數(shù)據(jù)探索,省去了很多不必要的操作。


          延伸閱讀??

          利用Python進(jìn)行數(shù)據(jù)分析》(原書第2版)

          干貨直達(dá)??


          更多精彩??

          在公眾號(hào)對(duì)話框輸入以下關(guān)鍵詞
          查看更多優(yōu)質(zhì)內(nèi)容!

          PPT | 讀書 | 書單 | 硬核 | 干貨 | 講明白 | 神操作
          大數(shù)據(jù) | 云計(jì)算 | 數(shù)據(jù)庫(kù) | Python | 爬蟲 | 可視化
          AI | 人工智能 | 機(jī)器學(xué)習(xí) | 深度學(xué)習(xí) | NLP
          5G | 中臺(tái) | 用戶畫像 1024 | 數(shù)學(xué) | 算法 數(shù)字孿生

          據(jù)統(tǒng)計(jì),99%的大咖都關(guān)注了這個(gè)公眾號(hào)
          ??
          瀏覽 14
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <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>
                  伊人国产女 | 国产无码精品黄色电影 | 国产美女精品久久久 | 欧美aaa国产aaa亚洲aaa免费看 | PORNY九色视频9l自拍 |