偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

太實(shí)用了!四種方法教你輕松制作交互式儀表板!

開(kāi)發(fā) 后端
在本文中,我給大家分享 4 款 Python 工具包,使用它們?yōu)閿?shù)據(jù)科學(xué)項(xiàng)目創(chuàng)建交互式儀表板非常的棒。

讓客戶深刻記住你的數(shù)據(jù)洞察和發(fā)現(xiàn)的最好方式,是創(chuàng)建交互式儀表板。為什么要互動(dòng)呢?一方面是比較有趣,另一方面是客戶對(duì)動(dòng)作的記憶比靜態(tài)的洞察力更深刻。

在本文中,我給大家分享 4 款 Python 工具包,使用它們?yōu)閿?shù)據(jù)科學(xué)項(xiàng)目創(chuàng)建交互式儀表板非常的棒。喜歡本文記得收藏、關(guān)注、點(diǎn)贊。

1、Widgets

Ipywidgets(縮寫(xiě)為 Widgets) 是一個(gè)代碼簡(jiǎn)單直觀的交互式包,它為 Jupyter Notebooks 中的 GUI 提供 HTML 架構(gòu)。

該包允許我們直接在 Jupyter Notebook 單元中創(chuàng)建交互式儀表板。

只需幾行代碼,你就可以將 Jupyter Notebook 改為儀表板。讓我用幾行代碼展示如何做到這一點(diǎn)。

首先,我們需要安裝所需的包。

pip install ipywidgets

然后,我們需要在 Jupyter Notebook 中啟用 Ipywidgets。要啟用它,請(qǐng)?jiān)诿钐崾痉袀鬟f以下代碼。

jupyter nbextension enable --py widgetsnbextension

我們可以在 Jupyter Notebook 中創(chuàng)建交互式儀表板,并配備所有必要的軟件包。我將使用泰坦尼克號(hào)樣本數(shù)據(jù)進(jìn)行舉例。

import seaborn as sns
titanic = sns.load_dataset('titanic')
titanic.head()

我想創(chuàng)建一個(gè)交互式儀表板,獲取按類別變量分組的泰坦尼克號(hào)票價(jià)平均值。在這種情況下,使用如下代碼:

#Creating the interactive dashboard
from ipywidgets import interact
@interact
def create_fare_plot(col = titanic.drop(['fare', 'age'], axis =1).columns):
sns.barplot(data = titanic, x = col, y ='fare')
plt.title(f'Mean Bar Plot of the Fare grouped by the {col}')

通過(guò)添加@interact代碼,我們啟動(dòng)了交互過(guò)程。

2、Voila

Voila-dashboards 是一個(gè)簡(jiǎn)單的 Python 包,它將一個(gè)簡(jiǎn)單的 Jupyter Notebook 變成一個(gè)漂亮的 Web 儀表板。

只需一行安裝代碼,我們就可以快速渲染 Jupyter Notebook。

讓我們安裝 Voila-dashboards。

pip install voila

完成 Voila 包的安裝后,刷新 Jupyter Notebook 并查看 notebook 選項(xiàng)卡。在那里你會(huì)發(fā)現(xiàn)一個(gè)新的 Voila 按鈕。

現(xiàn)在按下按鈕,即可自動(dòng)生成 Voila 儀表板。

3、Dash by Plotly

Dash by Plotly 是一個(gè)開(kāi)源 Python 包,它是基于 Plotly 可視化的低代碼框架包。

要試用 Dash,先安裝軟件包。

pip install dash

安裝完成后,我將使用以下代碼創(chuàng)建一個(gè)簡(jiǎn)單的 Titanic 儀表板。

import dash
from dash import dcc, html
import plotly.express as px
import pandas as pd
import seaborn as sns
app = dash.Dash()
df = sns.load_dataset('titanic')
fig = px.scatter(
df,
x="fare",
y="age",
size="pclass",
color="alive",
hover_name="embark_town",
log_x=True,
size_max=60
)
app.layout = html.Div(children = [
html.H1(children='Titanic Dashboard'),
dcc.Graph(id="fare_vs_age", figure=fig)])
if __name__ == "__main__":
app.run_server(debug=True)

運(yùn)行上述代碼后,將在默認(rèn)(http://127.0.0.1:8050/)中啟動(dòng)儀表板。

我們可以添加一個(gè)回調(diào)交互來(lái)讓用戶輸入具有特定的輸出。

import dash
from dash import dcc, html, Input, Output
import plotly.express as px
import pandas as pd
import seaborn as sns
app = dash.Dash()
df = sns.load_dataset('titanic')
fig = px.scatter(
df,
x="fare",
y="age",
size="pclass",
color="alive",
hover_name="embark_town",
log_x=True,
size_max=60
)
app.layout = html.Div(children = [
html.H1(children='Titanic Dashboard'),
dcc.Graph(id="fare_vs_age", figure=fig),
#Add interactive callback here
html.H4("Change the value in the text box to see callbacks in action"),
html.Div([
"Input: ",
dcc.Input(id='my-input', value='initial value', type='text')
]),
html.Br(),
html.Div(id='my-output'),
])
@app.callback(
Output(component_id='my-output', component_property='children'),
Input(component_id='my-input', component_property='value')
)
def update_output_div(input_value):
return f'Output: {input_value}'
if __name__ == "__main__":
app.run_server(debug=True)

Dash by Plotly 在創(chuàng)建儀表板時(shí)非常方便,它提供了許多有用的 API。

4、Streamlit

Streamlit 是一個(gè)開(kāi)源 Python 包,旨在為數(shù)據(jù)科學(xué)家和機(jī)器學(xué)習(xí)項(xiàng)目創(chuàng)建一個(gè) Web 應(yīng)用程序。

Streamlit 提供的 API 易于任何初學(xué)者使用,非常適合希望以交互方式構(gòu)建其數(shù)據(jù)組合的任何人。

讓我們先安裝 Streamlit 包。

pip install streamlit

安裝過(guò)程完成后,我們可以創(chuàng)建交互式儀表板。

讓我給你下面的代碼示例。

import streamlit as st
import pandas as pd
import plotly.express as px
import seaborn as sns
df = sns.load_dataset('titanic')
st.title('Titanic Dashboard')
st.subheader('Dataset')
st.dataframe(df)
st.subheader('Data Numerical Statistic')
st.dataframe(df.describe())
st.subheader('Data Visualization with respect to Survived')
left_column, right_column = st.columns(2)
with left_column:
'Numerical Plot'
num_feat = st.selectbox(
'Select Numerical Feature', df.select_dtypes('number').columns)
fig = px.histogram(df, x = num_feat, color = 'survived')
st.plotly_chart(fig, use_container_width=True)
with right_column:
'Categorical column'
cat_feat = st.selectbox(
'Select Categorical Feature', df.select_dtypes(exclude = 'number').columns)
fig = px.histogram(df, x =cat_feat, color = 'survived' )
st.plotly_chart(fig, use_container_width=True)

使用 VScode 將文件保存為 titanic_st.py,然后在終端中運(yùn)行該代碼。

streamlit run titanic_st.py

Streamlit 在上述地址上運(yùn)行,我們可以訪問(wèn)我們的儀表板。

使用上面的簡(jiǎn)單代碼,我們創(chuàng)建了一個(gè)交互式儀表板,API 并不難理解,我們只使用最少數(shù)量的代碼。

結(jié)論

當(dāng)我們需要展示數(shù)據(jù)科學(xué)項(xiàng)目時(shí)建議用交互式儀表板,它將改善大大改善用戶體驗(yàn)。

責(zé)任編輯:龐桂玉 來(lái)源: 簡(jiǎn)說(shuō)Python
相關(guān)推薦

2010-09-02 10:55:57

CSS

2010-03-15 10:01:26

Ubuntu 系統(tǒng)

2009-12-09 11:03:45

安裝Linux

2022-09-02 14:29:01

JavaScrip數(shù)組屬性

2014-03-17 09:22:43

Linux命令

2023-02-03 08:47:20

職位招聘難題

2020-08-10 00:30:55

備份密碼iPhone移動(dòng)安全

2009-02-25 09:52:14

類型轉(zhuǎn)換.NET 強(qiáng)制轉(zhuǎn)型

2009-03-31 13:12:30

解析XMLJava

2011-06-22 15:21:08

XML

2021-05-08 16:24:10

Windows 10Windows微軟

2021-08-12 13:00:56

物聯(lián)網(wǎng)IOT

2023-08-05 15:12:54

Kubernetes命令

2009-11-23 15:57:51

PHP偽靜態(tài)

2021-03-10 10:13:39

爬蟲(chóng)Python代碼

2010-07-16 13:50:53

Perl哈希表

2016-06-28 10:19:31

云計(jì)算云安全

2009-09-17 16:55:58

C#組件設(shè)計(jì)

2010-08-02 16:47:46

Flex

2021-09-03 11:24:04

云計(jì)算云計(jì)算環(huán)境云應(yīng)用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)