99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀用Python自制了一張網(wǎng)頁(yè),一鍵自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告
用Python自制了一張網(wǎng)頁(yè),一鍵自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告
2022-05-11
收藏

作者:俊欣

來(lái)源:關(guān)于數(shù)據(jù)分析與可視化

今天小編帶領(lǐng)大家用Python自制一個(gè)自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告這樣的一個(gè)工具,大家只需要在瀏覽器中輸入url便可以輕松的訪問(wèn),如下所示

用Python自制了一張網(wǎng)頁(yè),一鍵自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告

第一步

首先我們導(dǎo)入所要用到的模塊,設(shè)置網(wǎng)頁(yè)的標(biāo)題、工具欄以及l(fā)ogo的導(dǎo)入,代碼如下

from st_aggrid import AgGrid import streamlit as st import pandas as pd import pandas_profiling from streamlit_pandas_profiling import st_profile_report from pandas_profiling import ProfileReport from PIL import Image

st.set_page_config(layout='wide') #Choose wide mode as the default setting #Add a logo (optional) in the sidebar logo = Image.open(r'wechat_logo.jpg')
st.sidebar.image(logo,  width=120) #Add the expander to provide some information about the app with st.sidebar.expander("關(guān)于這個(gè)項(xiàng)目"):
     st.write("""
        該項(xiàng)目是將streamlit和pandas_profiling相結(jié)合,在您上傳數(shù)據(jù)集之后自動(dòng)生成相關(guān)的數(shù)據(jù)分析報(bào)告,當(dāng)然該項(xiàng)目提供了兩種模式 全量分析還是部分少量分析,這里推薦用部分少量分析,因?yàn)橛?jì)算量更少,所需要的時(shí)間更短,效率更高
     """) #Add an app title. Use css to style the title st.markdown(""" <style> .font {                                          
    font-size:30px ; font-family: 'Cooper Black'; color: #FF9633;} 
    </style> """, unsafe_allow_html=True)
st.markdown('<p class="font">請(qǐng)上傳您的數(shù)據(jù)集,該應(yīng)用會(huì)自動(dòng)生成相關(guān)的數(shù)據(jù)分析報(bào)告</p>', unsafe_allow_html=True)

output

用Python自制了一張網(wǎng)頁(yè),一鍵自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告

上傳文件以及變量的篩選

緊接的是我們需要上傳csv文件,代碼如下

uploaded_file = st.file_uploader("請(qǐng)上傳您的csv文件: ", type=['csv'])

我們可以選擇針對(duì)數(shù)據(jù)集當(dāng)中所有的特征進(jìn)行一個(gè)統(tǒng)計(jì)分析,或者只是針對(duì)部分的變量來(lái)一個(gè)數(shù)據(jù)分析,代碼如下

if uploaded_file is not None:
     df = pd.read_csv(uploaded_file)
     option1 = st.sidebar.radio( '您希望您的數(shù)據(jù)分析報(bào)告中包含哪些變量呢',
          ('所有變量', '部分變量')) if option1 == '所有變量':
          df = df elif option1 == '部分變量':
          var_list = list(df.columns)

要是用戶勾選的是部分變量,只是針對(duì)部分變量來(lái)進(jìn)行一個(gè)分析的話,就會(huì)彈出來(lái)一個(gè)多選框來(lái)供用戶選擇,代碼如下

var_list = list(df.columns)
option3 = st.sidebar.multiselect(
     '篩選出您希望在數(shù)據(jù)分析報(bào)告中包含的變量',
     var_list)
df = df[option3]

用戶可以挑選到底是“簡(jiǎn)單分析”或者是“完整分析”,要是勾選的是“完整分析”的話,會(huì)跳出相應(yīng)的提示,提示“完整分析”由于涉及到更加復(fù)雜的計(jì)算操作,耗時(shí)更加地長(zhǎng),要是遇到大型的數(shù)據(jù)集,還會(huì)有計(jì)算失敗的情況出現(xiàn)

option2 = st.sidebar.selectbox( '篩選模式,完整分析還是簡(jiǎn)單分析',
      ('簡(jiǎn)單分析', '完整分析')) if option2 == '完整分析':
      mode = 'complete' st.sidebar.warning( '完整分析由于涉及到更加復(fù)雜的計(jì)算操作,耗時(shí)更加地長(zhǎng),要是遇到大型的數(shù)據(jù)集,還會(huì)有計(jì)算失敗的情況出現(xiàn),這里推薦使用簡(jiǎn)單分析') elif option2 == '簡(jiǎn)單分析':
      mode = 'minimal' grid_response = AgGrid(
           df,
           editable=True,
           height=300,
           width='100%',
      )

      updated = grid_response['data']
      df1 = pd.DataFrame(updated)

當(dāng)用戶點(diǎn)擊“生成報(bào)告”的時(shí)候就會(huì)自動(dòng)生成一份完整的數(shù)據(jù)分析報(bào)告了,代碼如下

if st.button('生成報(bào)告'): if mode=='complete':
            profile=ProfileReport(df,
                title="User uploaded table",
                progress_bar=True,
                dataset={ "簡(jiǎn)介": '歡迎關(guān)注公眾號(hào):關(guān)于數(shù)據(jù)分析與可視化', "作者": '俊欣', "時(shí)間": '2022.05' })
            st_profile_report(profile) elif mode=='minimal':
            profile=ProfileReport(df1,
                minimal=True,
                title="User uploaded table",
                progress_bar=True,
                dataset={ "簡(jiǎn)介": '歡迎關(guān)注公眾號(hào):關(guān)于數(shù)據(jù)分析與可視化', "作者": '俊欣', "時(shí)間": '2022.05' })
            st_profile_report(profile)

最后出來(lái)的結(jié)果如下,這里再來(lái)顯示一遍

用Python自制了一張網(wǎng)頁(yè),一鍵自動(dòng)生成探索性數(shù)據(jù)分析報(bào)告

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見(jiàn):http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }