時間:2023-06-24 13:00:01 | 來源:網(wǎng)站運營
時間:2023-06-24 13:00:01 來源:網(wǎng)站運營
用Python自制了一張網(wǎng)頁,一鍵自動生成探索性數(shù)據(jù)分析報告:作者:俊欣from st_aggrid import AgGridimport streamlit as stimport pandas as pdimport pandas_profilingfrom streamlit_pandas_profiling import st_profile_reportfrom pandas_profiling import ProfileReportfrom PIL import Imagest.set_page_config(layout='wide') #Choose wide mode as the default setting#Add a logo (optional) in the sidebarlogo = Image.open(r'wechat_logo.jpg')st.sidebar.image(logo, width=120)#Add the expander to provide some information about the appwith st.sidebar.expander("關于這個項目"): st.write(""" 該項目是將streamlit和pandas_profiling相結合,在您上傳數(shù)據(jù)集之后自動生成相關的數(shù)據(jù)分析報告,當然該項目提供了兩種模式 全量分析還是部分少量分析,這里推薦用部分少量分析,因為計算量更少,所需要的時間更短,效率更高 """)#Add an app title. Use css to style the titlest.markdown(""" <style> .font { font-size:30px ; font-family: 'Cooper Black'; color: #FF9633;} </style> """, unsafe_allow_html=True)st.markdown('<p class="font">請上傳您的數(shù)據(jù)集,該應用會自動生成相關的數(shù)據(jù)分析報告</p>', unsafe_allow_html=True)
outputuploaded_file = st.file_uploader("請上傳您的csv文件: ", type=['csv'])
我們可以選擇針對數(shù)據(jù)集當中所有的特征進行一個統(tǒng)計分析,或者只是針對部分的變量來一個數(shù)據(jù)分析,代碼如下if uploaded_file is not None: df = pd.read_csv(uploaded_file) option1 = st.sidebar.radio( '您希望您的數(shù)據(jù)分析報告中包含哪些變量呢', ('所有變量', '部分變量')) if option1 == '所有變量': df = df elif option1 == '部分變量': var_list = list(df.columns)
要是用戶勾選的是部分變量,只是針對部分變量來進行一個分析的話,就會彈出來一個多選框來供用戶選擇,代碼如下var_list = list(df.columns)option3 = st.sidebar.multiselect( '篩選出您希望在數(shù)據(jù)分析報告中包含的變量', var_list)df = df[option3]
用戶可以挑選到底是“簡單分析”或者是“完整分析”,要是勾選的是“完整分析”的話,會跳出相應的提示,提示“完整分析”由于涉及到更加復雜的計算操作,耗時更加地長,要是遇到大型的數(shù)據(jù)集,還會有計算失敗的情況出現(xiàn)option2 = st.sidebar.selectbox( '篩選模式,完整分析還是簡單分析', ('簡單分析', '完整分析')) if option2 == '完整分析': mode = 'complete' st.sidebar.warning( '完整分析由于涉及到更加復雜的計算操作,耗時更加地長,要是遇到大型的數(shù)據(jù)集,還會有計算失敗的情況出現(xiàn),這里推薦使用簡單分析') elif option2 == '簡單分析': mode = 'minimal' grid_response = AgGrid( df, editable=True, height=300, width='100%', ) updated = grid_response['data'] df1 = pd.DataFrame(updated)
當用戶點擊“生成報告”的時候就會自動生成一份完整的數(shù)據(jù)分析報告了,代碼如下if st.button('生成報告'): if mode=='complete': profile=ProfileReport(df, title="User uploaded table", progress_bar=True, dataset={ "簡介": '歡迎關注公眾號:關于數(shù)據(jù)分析與可視化', "作者": '俊欣', "時間": '2022.05' }) st_profile_report(profile) elif mode=='minimal': profile=ProfileReport(df1, minimal=True, title="User uploaded table", progress_bar=True, dataset={ "簡介": '歡迎關注公眾號:關于數(shù)據(jù)分析與可視化', "作者": '俊欣', "時間": '2022.05' }) st_profile_report(profile)
最后出來的結果如下,這里再來顯示一遍關鍵詞:數(shù)據(jù),報告,分析
微信公眾號
版權所有? 億企邦 1997-2025 保留一切法律許可權利。