Cov txheej txheem:

COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python): 16 Cov Kauj Ruam
COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python): 16 Cov Kauj Ruam

Video: COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python): 16 Cov Kauj Ruam

Video: COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python): 16 Cov Kauj Ruam
Video: Data Visualization with Tableau! Animated Graphs 2024, Kaum ib hlis
Anonim
COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python)
COVID19 Dashboard ntawm Daim Ntawv Qhia Ntiaj Teb (siv Python)

Kuv paub yuav luag txhua tus ntawm peb paub cov ntaub ntawv feem ntau txog COVID19.

Thiab cov lus qhia no yog hais txog kev tsim daim ntawv qhia npuas, txhawm rau txheeb xyuas cov ntaub ntawv ntawm lub sijhawm tiag (ntawm rooj plaub) ntawm daim ntawv qhia ntiaj teb.

Kom yooj yim dua, kuv tau ntxiv qhov program rau Github repository:

github.com/backshell/COVID19dashboard

Khoom siv

Tsis muaj cov khoom siv xav tau xws li thiab peb yuav ua tag nrho lub khoos phis tawj siv los ntawm GoogleColab Phau Ntawv. Yog li gmail tus account yuav tsum txaus los pib nrog.

Colab Notebooks / Colaboratory yog Google txoj haujlwm tshawb fawb tsim los pab tshaj tawm kev kawm tshuab thiab kev tshawb fawb. Nws yog Jupyter phau ntawv ib puag ncig uas tsis xav tau teeb tsa los siv thiab ua tiav hauv huab.

Thiab TSIS muaj qhov teeb tsa xav tau hauv koj lub tshuab.

Kauj Ruam 1: Nkag Siab Cov Txheej Txheem Backend (database)

Feem ntau ntawm txhua qhov software program khaws cov ntaub ntawv los ntawm cov backend thiab cov txiaj ntsig tau tsim tawm thiab luam tawm rau pem hauv ntej. Thiab rau qhov haujlwm tshwj xeeb no, peb yuav xav tau COVID19 cov ntaub ntawv tiag.

The G. W. C. Whiting Tsev Kawm Ntawv ntawm Engineering tau tshaj tawm COVID -19 txheeb cais los ntawm nws tus lej github:

github.com/CSSEGISandData

Txij thaum pib txog hnub tim, COVID19 lub teb chaws cov ntaub ntawv txheeb cais tau tshaj tawm hauv cov chaw cia khoom.

Yog li peb yuav siv. CSV cov ntaub ntawv ntawm lawv (segmented row-wise of countries) thiab npaj cov ntaub ntawv hauv ntiaj teb daim ntawv qhia.

Kauj Ruam 2: Python Pob Ntawv/tsev qiv ntawv siv hauv Txoj Haujlwm

Hauv qab no yog cov npe pob khoom nab hab sej, uas peb yuav siv. Cia kuv muab cov ntsiab lus ntawm txhua lub hom phiaj ntawm lawv.

numpy:

NumPy yog lub tsev qiv ntawv rau Python cov lus siv lus, ntxiv kev txhawb nqa rau cov chav loj, ntau qhov ntau thiab cov lej, nrog rau kev sau ntau ntawm cov lej qib siab ua haujlwm los ua haujlwm ntawm cov pawg no.

pandas:

pandas yog lub tsev qiv ntawv software sau rau Python programming lus rau kev tswj cov ntaub ntawv thiab tshuaj xyuas.

matplotlib.pyplot:

pyplot feem ntau yog npaj rau cov phiaj xwm sib tham thiab cov xwm txheej yooj yim ntawm cov phiaj xwm phiaj xwm tsim tawm

plotly.express:

Plotly Express yog qib tshiab Python kev pom lub tsev qiv ntawv. Cov syntax yooj yim rau cov kab kos nyuaj.

folium:

folium ua kom yooj yim rau pom cov ntaub ntawv uas tau siv hauv Python ntawm daim ntawv qhia sib tham sib tham

plotly.graph_objects:

Cov phiaj xwm sej Python muaj los tsim, tswj thiab ua cov duab nraaj (piv txwv li kab kos, cov phiaj xwm, daim duab qhia chaw thiab daim duab duab) sawv cev los ntawm cov ntaub ntawv teeb tsa kuj tseem hu ua cov duab.

seaborn:

Seaborn yog Python cov ntaub ntawv pom pom lub tsev qiv ntawv raws matplotlib. Nws muab cov qib siab sib cuam tshuam rau kev kos duab zoo nkauj thiab qhia paub cov duab nraaj.

ipywidgets: cov

ipywidgets yog sib tham sib HTML widgets rau Jupyter notebooks, JupyterLab thiab IPython kernel. Phau ntawv sau los muaj txoj sia thaum sib tham sib tham tau siv.

Txhim kho cov pob no tsis xav tau vim peb yuav ua haujlwm txoj haujlwm no tag nrho hauv Google Colab Phau Ntawv (cia nws khaws nws ua colab thoob plaws cov lus qhia no).

Kauj Ruam 3: Teeb Koj Lub Tsav Tsheb, Siv Colab

Teeb Koj Tus Tsav Tsheb, Siv Colab
Teeb Koj Tus Tsav Tsheb, Siv Colab
Teeb Koj Tus Tsav Tsheb, Siv Colab
Teeb Koj Tus Tsav Tsheb, Siv Colab

Hauv koj li Drive, Tsim ib daim nplaub tshev rau koj phau ntawv sau.

Hais lus thev naus laus zis, cov kauj ruam no tsis tas yuav tsum yog koj xav pib ua haujlwm hauv Colab. Txawm li cas los xij, txij li Colab tab tom ua haujlwm ntawm koj lub tsav, nws tsis yog lub tswv yim phem los qhia lub nplaub tshev uas koj xav ua haujlwm. Koj tuaj yeem ua li ntawd los ntawm kev mus rau koj li Google Drive thiab nyem "Tshiab" thiab tom qab ntawd tsim daim nplaub tshev tshiab.

Tom qab ntawd koj tuaj yeem xaiv los tsim colabnotebook ntawm no lossis pib ua haujlwm ncaj qha ua haujlwm hauv colab thiab txuas cov ntawv tais ceev tseg hauv tsav, uas yog tsim rau kev ua haujlwm colab.

Qhov no yog kev xyaum ua tau zoo, lwm qhov ntxiv cov colab peb tsim nws yuav zoo li tsis meej pem hauv peb txoj kev tsav.

Kauj Ruam 4: Txheej txheem cej luam ntawm Txoj Haujlwm

Hauv qhov haujlwm no/phau ntawv sau, peb yuav tsim cov hauv qab no rau COVID-19:

  • Cov Npe Ntawm Lub Tebchaws los ntawm Tus Zauv Cov Ntaub Ntawv
  • Cov Ntaub Ntawv Tag Nrho ntawm Daim Ntawv Qhia Ntiaj Teb

Kauj Ruam 5: COVID-19 Dashboard | Tshooj 1

COVID-19 Dashboard | Tshooj 1
COVID-19 Dashboard | Tshooj 1

Koj tuaj yeem siv yav tom ntej los pab txhawm rau xa koj cov cai los ntawm Python 2 mus rau Python 3 hnub no - thiab tseem muaj nws khiav ntawm Python 2.

Yog tias koj twb muaj Python 3 code, koj tuaj yeem siv yav tom ntej los muab Python 2 sib xws nrog yuav luag tsis muaj haujlwm ntxiv.

yav tom ntej txhawb cov txheej txheem kev rov txhim kho tsev qiv ntawv (PEP 3108) los ntawm ib qho ntawm ob peb lub tswv yim, tso cai feem ntau tau txav cov tsev qiv ntawv tus qauv nkag mus rau hauv lawv li Python 3 lub npe thiab chaw nyob hauv Python 2.

Kauj Ruam 6: COVID-19 Dashboard | Tshooj 2

COVID-19 Dashboard | Tshooj 2
COVID-19 Dashboard | Tshooj 2

Kev ua haujlwm sib cuam tshuam (ipywidgets.interact) cia li tsim cov neeg siv interface (UI) tswj rau kev tshawb nrhiav cov cai thiab cov ntaub ntawv sib cuam tshuam. Nws yog txoj hauv kev yooj yim tshaj plaws los pib siv IPython cov cuab yeej.

Kauj Ruam 7: COVID-19 Dashboard | Tshooj 3

COVID-19 Dashboard | Tshooj 3
COVID-19 Dashboard | Tshooj 3

display_html qhia txog HTML sawv cev ntawm ib yam khoom. Ntawd yog, nws saib mus rau npe tso saib cov txheej txheem, xws li _repr_html_, thiab hu lawv, tso tawm qhov tshwm sim, yog tias muaj.

Kauj Ruam 8: COVID-19 Dashboard | Tshooj 4

COVID-19 Dashboard | Tshooj 4
COVID-19 Dashboard | Tshooj 4

Cov npe ntawm pob khoom (raws li tau piav qhia hauv qib 2) tau txais cov khoom xa tuaj rau hauv qhov program.

Kauj Ruam 9: COVID-19 Dashboard | Tshooj 5

death_df = pd.read_csv ('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv')

confirm_df = pd.read_csv ('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv')

recovered_df = pd.read_csv ('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv')

country_df = pd.read_csv ('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/web-data/data/cases_country.csv')

Raws li tau piav qhia hauv qib 1, nyeem cov ntaub ntawv raws li.csv cov ntaub ntawv los ntawm lub chaw cia khoom.

Kauj ruam 10: COVID-19 Dashboard | Tshooj 6

COVID-19 Dashboard | Tshooj 6
COVID-19 Dashboard | Tshooj 6

Peb yuav hloov npe cov npe df rau cov ntawv me

Kauj Ruam 11: COVID-19 Dashboard | Tshooj 7

COVID-19 Dashboard | Tshooj 7
COVID-19 Dashboard | Tshooj 7

Peb yuav hloov lub xeev/xeev rau lub xeev thiab lub tebchaws/cheeb tsam mus rau lub tebchaws

Kauj Ruam 12: COVID-19 Dashboard | Tshooj 8

COVID-19 Dashboard | Tshooj 8
COVID-19 Dashboard | Tshooj 8

Peb yuav suav tag nrho cov naj npawb ntawm qhov tau lees paub, tuag thiab rov zoo.

Kauj Ruam 13: COVID-19 Dashboard | Tshooj 9

COVID-19 Dashboard | Tshooj 9
COVID-19 Dashboard | Tshooj 9
COVID-19 Dashboard | Tshooj 9
COVID-19 Dashboard | Tshooj 9

Peb yuav nthuav tawm tag nrho cov txheeb cais hauv HTML hom, raws li peb tau xa cov tsev qiv ntawv tshwj xeeb hauv qib 7 ua ntej raws li hauv qab no:

los ntawm IPython.core.display ntshuam zaub, HTML

Kauj Ruam 14: Cov Npe Ntawm Lub Tebchaws (Top10) los ntawm Tus Naj Npawb | COVID-19 Dashboard

Cov Npe Ntawm Lub Tebchaws (Top10) los ntawm Tus Zauv Cov Ntaub Ntawv | COVID-19 Dashboard
Cov Npe Ntawm Lub Tebchaws (Top10) los ntawm Tus Zauv Cov Ntaub Ntawv | COVID-19 Dashboard
Cov Npe Ntawm Lub Tebchaws (Top10) los ntawm Tus Zauv Cov Ntaub Ntawv | COVID-19 Dashboard
Cov Npe Ntawm Lub Tebchaws (Top10) los ntawm Tus Zauv Cov Ntaub Ntawv | COVID-19 Dashboard

fig = go. FigureWidget (txheej txheem = mus. Layout ())

FigureWidget muaj nuj nqi rov qab ib qho khoom tsis muaj FigureWidget nrog lub neej ntawd x thiab y axes. Jupyter sib tham sib widgets muaj tus cwj pwm txheej txheem nthuav tawm tus lej CSS cov khoom uas cuam tshuam li cas cov cuab yeej raug tso tawm.

pd. DataFrame

tsim dataframe siv phau ntawv txhais lus, nrog peb xim keeb kwm yav dhau los rau qhov tshwm sim kom muaj neeg nyob.

def show_latest_cases (TOP)

txheeb cov txiaj ntsig los ntawm kev lees paub nqis nqis.

sib tham (show_latest_cases, TOP = '10 ')

Kev ua haujlwm sib cuam tshuam (ipywidgets.interact) cia li tsim cov neeg siv interface (UI) tswj rau kev tshawb nrhiav cov cai thiab cov ntaub ntawv sib cuam tshuam.

ipywLayout = widgets. Layout (ciam teb = 'khoom 2px ntsuab')

tsim ciam teb nrog 2px dav kab ntawm cov xim ntsuab, rau qhov tshwm sim los tso saib.

Kauj Ruam 15: Cov Ntaub Ntawv Tag Nrho ntawm Daim Ntawv Qhia Ntiaj Teb | COVID-19 Dashboard

Cov Ntaub Ntawv Tag Nrho Hauv Ntiaj Teb Daim Ntawv Qhia | COVID-19 Dashboard
Cov Ntaub Ntawv Tag Nrho Hauv Ntiaj Teb Daim Ntawv Qhia | COVID-19 Dashboard
Cov Ntaub Ntawv Tag Nrho Hauv Ntiaj Teb Daim Ntawv Qhia | COVID-19 Dashboard
Cov Ntaub Ntawv Tag Nrho Hauv Ntiaj Teb Daim Ntawv Qhia | COVID-19 Dashboard

world_map = folium. Map (qhov chaw = [11, 0], vuas = "cartodbpositron", zoom_start = 2, max_zoom = 6, min_zoom = 2)

Folium yog cov cuab yeej uas ua rau koj zoo li daim duab qhia Vajtswv thaum txhua txoj haujlwm tau ua tiav nyob rau sab tom qab. Nws yog Python qhwv rau cov cuab yeej hu ua leaflet.js. Peb pib muab nws cov lus qhia tsawg kawg, JS ua haujlwm ntau nyob rau tom qab thiab peb tau txais qee daim duab qhia chaw zoo heev. Nws yog khoom zoo. Kom paub meej, daim ntawv qhia kev yog hu ua 'Leaflet Map'. Cov cuab yeej uas cia koj hu lawv hauv Python hu ua 'Folium'.

Folium ua kom yooj yim rau pom cov ntaub ntawv uas tau siv hauv Python ntawm daim ntawv qhia sib tham sib Leaflet. Nws ua rau ob qho kev khi ntawm cov ntaub ntawv rau hauv daim duab qhia chaw rau choropleth pom kev zoo ib yam li dhau Vincent/Vega pom kev zoo li cov cim ntawm daim duab qhia chaw.

rau kuv hauv ntau (0, len (confirm_df))

Hauv lub voj, peb yuav tau txais txhua qhov xwm txheej uas tau lees paub los ntawm qib 9 kev tsim qauv.

folium. Circle

Peb tsim daim ntawv qhia npuas los ntawm kev siv folium. Circle () kom rov ua haujlwm ntxiv.

qhov chaw = [tau lees paub_df.iloc ['lat'], lees paub_df.iloc ['ntev'], los ntawm kev lees paub_df ntawm cov xwm txheej tau lees paub los ntawm qib 5, peb rho tawm qhov latitude thiab longitude qhov tseem ceeb sib xws rau txhua qhov chaw/cov ntaub ntawv hauv tebchaws.

radius = (int ((np.log (confirm_df.iloc [i, -1] +1.00001))))+0.2)*50000, tsim cov khoom siv voos kheej kheej los npaj cov voj voos ntawm lub ntiaj teb daim ntawv qhia thoob plaws lub tebchaws.

xim = 'liab', fill_color = 'indigo', ua cov txheej txheem ntawm lub voj voog ua xim liab thiab thaj tsam sab hauv zoo li indigo.

thiab thaum kawg npaj lub voj voog ntawm lub ntiaj teb_map siv cov cuab yeej tooltip.

Kauj Ruam 16: Qhov tshwm sim

Qhov tshwm sim!
Qhov tshwm sim!
Qhov tshwm sim!
Qhov tshwm sim!

Cov ntawv txuas nrog:

  1. Cov Npe Ntawm Lub Tebchaws los ntawm Tus Zauv Cov Ntaub Ntawv
  2. Cov Ntaub Ntawv Tag Nrho ntawm Daim Ntawv Qhia Ntiaj Teb

Pom zoo: