Cov txheej txheem:

Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python: 6 Cov Kauj Ruam
Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python: 6 Cov Kauj Ruam

Video: Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python: 6 Cov Kauj Ruam

Video: Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python: 6 Cov Kauj Ruam
Video: Tik Tok || Tseem Nco Koj Thiab Kuv P15 2024, Kaum ib hlis
Anonim
Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python
Teeb Duab Kub Hloov Los Ntawm Kev Hloov Pauv Hauv Python

Kev Hloov Huab Cua yog teeb meem loj. Thiab ntau tus neeg tsis tam sim no ntau npaum li cas nws nce. Hauv cov lus qhia no, peb yuav teeb tsa qhov ntsuas kub hloov pauv hauv huab cua vim kev hloov pauv huab cua. Txog daim ntawv dag, koj tuaj yeem saib cov ntaub ntawv nab nab hauv qab no.

Khoom siv

Koj yuav tsum tau:

  • Tus Code Editor (Kuv siv lub zej zog version ntawm PyCharm)
  • Python v3.8 lossis tshiab dua

Kauj ruam 1: Rub tawm Cov Ntaub Ntawv

Ua ntej, koj yuav tsum rub tawm cov ntaub ntawv. Yog tias koj xav teeb lwm yam, koj tuaj yeem siv cov ntaub ntawv sib txawv. Kuv siv cov ntaub ntawv los ntawm NOAA. Ntawm no yog cov ntaub ntawv. Koj tuaj yeem nkag mus rau koj tus kheej qhov kev ntsuas tsis raug thiab tom qab ntawd nyem cov phiaj, nqes mus, thiab koj yuav pom lub cim nrog cov ntawv thiab X nyob rau sab laug sab saum toj ntawm lub rooj. Txhawm rau kom ntseeg tau tias nws raug, nyem rau nws thiab nws yuav tsum hais rub cov ntaub ntawv hauv hom CSV. Kuj tseem muaj lwm cov ntaub ntawv csv kuv tau muab tso rau hauv qab no uas koj tuaj yeem siv tau.

Kauj Ruam 2: Tshaj Tawm Koj Cov Ntaub Ntawv rau Koj li Python Project

Hloov koj cov ntaub ntawv rau koj li Python Project
Hloov koj cov ntaub ntawv rau koj li Python Project

Txhawm rau xa koj cov ntaub ntawv mus rau qhov haujlwm ua nab nab, ua ntej, xyuas kom nws nyob hauv tib lub nplaub tshev ntawm koj lub computer. Tom ntej no, ntaus, file = qhib ("Lub npe ntawm Dataset", "r")

cov ntaub ntawv = file.readlines ()

Txoj haujlwm qhib qhib cov ntaub ntawv thiab r yog rau nyeem. Txawm hais tias cov ntaub ntawv tau qhib, qhov no tsuas yog txhais tau tias koj tuaj yeem nyeem nws yog li peb tsim lwm qhov sib txawv hu ua cov ntaub ntawv, uas nyeem cov ntawv.

Peb tom ntej tsim qhov sib txawv xyoo. Nov yog kab ntawv xyoo ntawm cov ntaub ntawv thiab yuav khaws cia. Yog li peb ntaus, xyoo =

Kauj Ruam 3: Ntxiv Xyoo Kab Ntawv rau Xyoo Hloov Pauv

Ntxiv Cov Ntawv Xyoo rau Cov Xyoo Hloov Pauv
Ntxiv Cov Ntawv Xyoo rau Cov Xyoo Hloov Pauv

Txhawm rau ntxiv cov kab xyoo mus rau qhov sib txawv xyoo, peb khiav lub voj.

rau kab hauv cov ntaub ntawv: years.append (int (line.split (',') [0]))

Lub voj rau khiav lub voj rau txhua kab. xyoo.append txuas ntxiv dab tsi hauv kab lus. Lub luag haujlwm int hloov pauv dab tsi hauv kab lus rau ib tus lej. Line.split (",") yuav faib cov ntsiab lus ntawm kab sib cais ntawm tus lej thiab xa rov qab ib qho array, yog li peb tso [0] thaum kawg kom tau txais thawj lub ntsiab lus hauv kab lus, xyoo.

Kauj Ruam 4: Tsim Kom Muaj Kub Kub Variale thiab Ntxiv Qhov Kub Rau Nws

Tsim kom muaj Kub Kub Variale thiab Ntxiv Qhov Kub Rau Nws
Tsim kom muaj Kub Kub Variale thiab Ntxiv Qhov Kub Rau Nws

Vim tias peb cov ntaub ntawv.csv tau cais los ntawm kab, kom pom muaj kab tshiab, peb muaj / n qhov kawg ntawm txhua kab los sawv cev rau kab tshiab. Qhov no txhais tau tias peb yuav tsum ua haujlwm me ntsis ntxiv kom tau txais qhov ntsuas kub los ntawm cov ntaub ntawv. Peb pib nrog tib txoj cai.

ntev =

rau kab hauv cov ntaub ntawv:

numlist = line.split (',') [1].split ()

Daim ntawv ceeb toom tias peb muaj thib ob.slit kawg ntawm kab kawg. Qhov no yuav rhuav nws rau txhua tus cim yog li yog peb muaj lo lus nyob zoo nws yuav dhau h, e, l, l, o. Peb tom ntej yuav tsum tau txais tsuas yog qhov ntsuas kub los ntawm cov lej teev.

num = float (''. join (numlist)) temp.append (num)

Tus lej sib txawv tau hloov pauv qhov sib koom ua ke ntawm cov lej numlist rau ntab. Raws li peb tau kawm zaj lus kawg, qhov.append method txuas ntxiv nws mus rau qhov array.

Kauj Ruam 5: Ntshuam Pyplot Los ntawm Matplotlib

Ntshuam Pyplot Los ntawm Matplotlib
Ntshuam Pyplot Los ntawm Matplotlib

Txhawm rau teeb tsa qhov kub, koj yuav tsum ntshuam Pyplot.

los ntawm matplotlib ntshuam pyplot li plt

Qhov no tam sim no ntxiv Pyplot rau koj txoj haujlwm thiab siv ib qho ntawm nws cov haujlwm uas koj hu ua plt. functionName ().

Kauj Ruam 6: Teeb duab

Teeb duab
Teeb duab

Txhawm rau kos nws peb hu lub luag haujlwm muaj nuj nqi. Tom qab ntawd peb hu xlabel thiab ylabel los sau peb cov duab.

plt.plot (xyoo, sijhawm)

plt.ylabel ('Kub (C)')

plt.xlabel ('Xyoo')

plt.show ()

Kev ua yeeb yam qhia pom lub teeb.

Pom zoo: