6

## 最近寫的一個投資策略的python程式碼 希望知道如何改善

``````# 這邊輸入想要投資的金額，預設100萬

Money=1000000

import pandas as pd

print(df[0])

zz =pd.DataFrame(df[0])

#刪除資料的%，讓它變數值，找了很久才知道怎麼删，但試很久不會删整欄，只好土法煉鋼一個一個删
#MarketValue/100是為了把%變成小數點之後做運算

MarketValue1 = float(zz.at[0, '市值佔大盤比重'].strip('%'))
Value1=MarketValue1/100

MarketValue2 = float(zz.at[1, '市值佔大盤比重'].strip('%'))
Value2=MarketValue2/100

MarketValue3 = float(zz.at[2, '市值佔大盤比重'].strip('%'))
Value3=MarketValue3/100

MarketValue4 = float(zz.at[3, '市值佔大盤比重'].strip('%'))
Value4=MarketValue4/100

MarketValue5 = float(zz.at[4, '市值佔大盤比重'].strip('%'))
Value5=MarketValue5/100

MarketValue6 = float(zz.at[5, '市值佔大盤比重'].strip('%'))
Value6=MarketValue6/100

MarketValue7 = float(zz.at[6, '市值佔大盤比重'].strip('%'))
Value7=MarketValue7/100

MarketValue8 = float(zz.at[7, '市值佔大盤比重'].strip('%'))
Value8=MarketValue8/100

MarketValue9 = float(zz.at[8, '市值佔大盤比重'].strip('%'))
Value9=MarketValue9/100

MarketValue10 = float(zz.at[9, '市值佔大盤比重'].strip('%'))
Value10=MarketValue10/100

MarketValue11 = float(zz.at[10, '市值佔大盤比重'].strip('%'))
Value11=MarketValue11/100

MarketValue12 = float(zz.at[11, '市值佔大盤比重'].strip('%'))
Value12=MarketValue12/100

MarketValue13 = float(zz.at[12, '市值佔大盤比重'].strip('%'))
Value13=MarketValue13/100

MarketValue14 = float(zz.at[13, '市值佔大盤比重'].strip('%'))
Value14=MarketValue14/100

MarketValue15 = float(zz.at[14, '市值佔大盤比重'].strip('%'))
Value15=MarketValue15/100

MarketValue16 = float(zz.at[15, '市值佔大盤比重'].strip('%'))
Value16=MarketValue16/100

MarketValue17 = float(zz.at[16, '市值佔大盤比重'].strip('%'))
Value17=MarketValue17/100

MarketValue18 = float(zz.at[17, '市值佔大盤比重'].strip('%'))
Value18=MarketValue18/100

MarketValue19 = float(zz.at[18, '市值佔大盤比重'].strip('%'))
Value19=MarketValue19/100

MarketValue20 = float(zz.at[19, '市值佔大盤比重'].strip('%'))
Value20=MarketValue20/100

MarketValue21 = float(zz.at[20, '市值佔大盤比重'].strip('%'))
Value21=MarketValue21/100

MarketValue22 = float(zz.at[21, '市值佔大盤比重'].strip('%'))
Value22=MarketValue22/100

MarketValue23 = float(zz.at[22, '市值佔大盤比重'].strip('%'))
Value23=MarketValue23/100

MarketValue24 = float(zz.at[23, '市值佔大盤比重'].strip('%'))
Value24=MarketValue24/100

MarketValue25 = float(zz.at[24, '市值佔大盤比重'].strip('%'))
Value25=MarketValue25/100

MarketValue26 = float(zz.at[25, '市值佔大盤比重'].strip('%'))
Value26=MarketValue26/100

MarketValue27 = float(zz.at[26, '市值佔大盤比重'].strip('%'))
Value27=MarketValue27/100

MarketValue28 = float(zz.at[27, '市值佔大盤比重'].strip('%'))
Value28=MarketValue28/100

MarketValue29 = float(zz.at[28, '市值佔大盤比重'].strip('%'))
Value29=MarketValue29/100

MarketValue30 = float(zz.at[29, '市值佔大盤比重'].strip('%'))
Value30=MarketValue30/100

MarketValue31 = float(zz.at[30, '市值佔大盤比重'].strip('%'))
Value31=MarketValue31/100

MarketValue32 = float(zz.at[31, '市值佔大盤比重'].strip('%'))
Value32=MarketValue32/100

MarketValue33 = float(zz.at[32, '市值佔大盤比重'].strip('%'))
Value33=MarketValue33/100

MarketValue34 = float(zz.at[33, '市值佔大盤比重'].strip('%'))
Value34=MarketValue34/100

MarketValue35 = float(zz.at[34, '市值佔大盤比重'].strip('%'))
Value35=MarketValue35/100

MarketValue36 = float(zz.at[35, '市值佔大盤比重'].strip('%'))
Value36=MarketValue36/100

MarketValue37 = float(zz.at[36, '市值佔大盤比重'].strip('%'))
Value37=MarketValue37/100

MarketValue38 = float(zz.at[37, '市值佔大盤比重'].strip('%'))
Value38=MarketValue38/100

MarketValue39 = float(zz.at[38, '市值佔大盤比重'].strip('%'))
Value39=MarketValue39/100

MarketValue40 = float(zz.at[39, '市值佔大盤比重'].strip('%'))
Value40=MarketValue40/100

MarketValue41 = float(zz.at[40, '市值佔大盤比重'].strip('%'))
Value41=MarketValue41/100

MarketValue42 = float(zz.at[41, '市值佔大盤比重'].strip('%'))
Value42=MarketValue42/100

MarketValue43 = float(zz.at[42, '市值佔大盤比重'].strip('%'))
Value43=MarketValue43/100

MarketValue44 = float(zz.at[43, '市值佔大盤比重'].strip('%'))
Value44=MarketValue44/100

MarketValue45 = float(zz.at[44, '市值佔大盤比重'].strip('%'))
Value45=MarketValue45/100

MarketValue46 = float(zz.at[45, '市值佔大盤比重'].strip('%'))
Value46=MarketValue46/100

MarketValue47 = float(zz.at[46, '市值佔大盤比重'].strip('%'))
Value47=MarketValue47/100

MarketValue48 = float(zz.at[47, '市值佔大盤比重'].strip('%'))
Value48=MarketValue48/100

MarketValue49 = float(zz.at[48, '市值佔大盤比重'].strip('%'))
Value49=MarketValue49/100

MarketValue50 = float(zz.at[49, '市值佔大盤比重'].strip('%'))
Value50=MarketValue50/100

#算出前50支股票的市值總合
SumValue=(
Value1
+Value2
+Value3
+Value4
+Value5
+Value6
+Value7
+Value8
+Value9
+Value10
+Value11
+Value12
+Value13
+Value14
+Value15
+Value16
+Value17
+Value18
+Value19
+Value20
+Value21
+Value22
+Value23
+Value24
+Value25
+Value26
+Value27
+Value28
+Value29
+Value30
+Value31
+Value32
+Value33
+Value34
+Value35
+Value36
+Value37
+Value38
+Value39
+Value40
+Value41
+Value42
+Value43
+Value44
+Value45
+Value46
+Value47
+Value48
+Value49
+Value50)

#策略是很單純的等比例放大，所以1/市值總和

#等比例放大就會是股票的權重
#市值*等比例放大的比重

#股票名稱
F1=zz.at[0,'名稱']
F2=zz.at[1,'名稱']
F3=zz.at[2,'名稱']
F4=zz.at[3,'名稱']
F5=zz.at[4,'名稱']
F6=zz.at[5,'名稱']
F7=zz.at[6,'名稱']
F8=zz.at[7,'名稱']
F9=zz.at[8,'名稱']
F10=zz.at[9,'名稱']
F11=zz.at[10,'名稱']
F12=zz.at[11,'名稱']
F13=zz.at[12,'名稱']
F14=zz.at[13,'名稱']
F15=zz.at[14,'名稱']
F16=zz.at[15,'名稱']
F17=zz.at[16,'名稱']
F18=zz.at[17,'名稱']
F19=zz.at[18,'名稱']
F20=zz.at[19,'名稱']
F21=zz.at[20,'名稱']
F22=zz.at[21,'名稱']
F23=zz.at[22,'名稱']
F24=zz.at[23,'名稱']
F25=zz.at[24,'名稱']
F26=zz.at[25,'名稱']
F27=zz.at[26,'名稱']
F28=zz.at[27,'名稱']
F29=zz.at[28,'名稱']
F30=zz.at[29,'名稱']
F31=zz.at[30,'名稱']
F32=zz.at[31,'名稱']
F33=zz.at[32,'名稱']
F34=zz.at[33,'名稱']
F35=zz.at[34,'名稱']
F36=zz.at[35,'名稱']
F37=zz.at[36,'名稱']
F38=zz.at[37,'名稱']
F39=zz.at[38,'名稱']
F40=zz.at[39,'名稱']
F41=zz.at[40,'名稱']
F42=zz.at[41,'名稱']
F43=zz.at[42,'名稱']
F44=zz.at[43,'名稱']
F45=zz.at[44,'名稱']
F46=zz.at[45,'名稱']
F47=zz.at[46,'名稱']
F48=zz.at[47,'名稱']
F49=zz.at[48,'名稱']
F50=zz.at[49,'名稱']

#投資金額*權重，就是這支股票要投資的金額
B1=Money*A1
B2=Money*A2
B3=Money*A3
B4=Money*A4
B5=Money*A5
B6=Money*A6
B7=Money*A7
B8=Money*A8
B9=Money*A9
B10=Money*A10
B11=Money*A11
B12=Money*A12
B13=Money*A13
B14=Money*A14
B15=Money*A15
B16=Money*A16
B17=Money*A17
B18=Money*A18
B19=Money*A19
B20=Money*A20
B21=Money*A21
B22=Money*A22
B23=Money*A23
B24=Money*A24
B25=Money*A25
B26=Money*A26
B27=Money*A27
B28=Money*A28
B29=Money*A29
B30=Money*A30
B31=Money*A31
B32=Money*A32
B33=Money*A33
B34=Money*A34
B35=Money*A35
B36=Money*A36
B37=Money*A37
B38=Money*A38
B39=Money*A39
B40=Money*A40
B41=Money*A41
B42=Money*A42
B43=Money*A43
B44=Money*A44
B45=Money*A45
B46=Money*A46
B47=Money*A47
B48=Money*A48
B49=Money*A49
B50=Money*A50

#股票的代號可以當證券API的參數
C1=zz.at[0, '代號']
C2=zz.at[1, '代號']
C3=zz.at[2, '代號']
C4=zz.at[3, '代號']
C5=zz.at[4, '代號']
C6=zz.at[5, '代號']
C7=zz.at[6, '代號']
C8=zz.at[7, '代號']
C9=zz.at[8, '代號']
C10=zz.at[9, '代號']
C11=zz.at[10, '代號']
C12=zz.at[11, '代號']
C13=zz.at[12, '代號']
C14=zz.at[13, '代號']
C15=zz.at[14, '代號']
C16=zz.at[15, '代號']
C17=zz.at[16, '代號']
C18=zz.at[17, '代號']
C19=zz.at[18, '代號']
C20=zz.at[19, '代號']
C21=zz.at[20, '代號']
C22=zz.at[21, '代號']
C23=zz.at[22, '代號']
C24=zz.at[23, '代號']
C25=zz.at[24, '代號']
C26=zz.at[25, '代號']
C27=zz.at[26, '代號']
C28=zz.at[27, '代號']
C29=zz.at[28, '代號']
C30=zz.at[29, '代號']
C31=zz.at[30, '代號']
C32=zz.at[31, '代號']
C33=zz.at[32, '代號']
C34=zz.at[33, '代號']
C35=zz.at[34, '代號']
C36=zz.at[35, '代號']
C37=zz.at[36, '代號']
C38=zz.at[37, '代號']
C39=zz.at[38, '代號']
C40=zz.at[39, '代號']
C41=zz.at[40, '代號']
C42=zz.at[41, '代號']
C43=zz.at[42, '代號']
C44=zz.at[43, '代號']
C45=zz.at[44, '代號']
C46=zz.at[45, '代號']
C47=zz.at[46, '代號']
C48=zz.at[47, '代號']
C49=zz.at[48, '代號']
C50=zz.at[49, '代號']

#這是根據我策略做的次級版的策略，我想要用這筆資料得出的代號當爬蟲的變數去爬當下的股價，在用投資金額除以當下股價，這樣就是股票的股數

import requests
import bs4
url1='https://histock.tw/stock/' + str(C1)
url2='https://histock.tw/stock/' + str(C2)
url3='https://histock.tw/stock/' + str(C3)
url4='https://histock.tw/stock/' + str(C4)
url5='https://histock.tw/stock/' + str(C5)
url6='https://histock.tw/stock/' + str(C6)
url7='https://histock.tw/stock/' + str(C7)
url8='https://histock.tw/stock/' + str(C8)
url9='https://histock.tw/stock/' + str(C9)
url10='https://histock.tw/stock/' + str(C10)
url11='https://histock.tw/stock/' + str(C11)
url12='https://histock.tw/stock/' + str(C12)
url13='https://histock.tw/stock/' + str(C13)
url14='https://histock.tw/stock/' + str(C14)
url15='https://histock.tw/stock/' + str(C15)
url16='https://histock.tw/stock/' + str(C16)
url17='https://histock.tw/stock/' + str(C17)
url18='https://histock.tw/stock/' + str(C18)
url19='https://histock.tw/stock/' + str(C19)
url20='https://histock.tw/stock/' + str(C20)
url21='https://histock.tw/stock/' + str(C21)
url22='https://histock.tw/stock/' + str(C22)
url23='https://histock.tw/stock/' + str(C23)
url24='https://histock.tw/stock/' + str(C24)
url25='https://histock.tw/stock/' + str(C25)
url26='https://histock.tw/stock/' + str(C26)
url27='https://histock.tw/stock/' + str(C27)
url28='https://histock.tw/stock/' + str(C28)
url29='https://histock.tw/stock/' + str(C29)
url30='https://histock.tw/stock/' + str(C30)
url31='https://histock.tw/stock/' + str(C31)
url32='https://histock.tw/stock/' + str(C32)
url33='https://histock.tw/stock/' + str(C33)
url34='https://histock.tw/stock/' + str(C34)
url35='https://histock.tw/stock/' + str(C35)
url36='https://histock.tw/stock/' + str(C36)
url37='https://histock.tw/stock/' + str(C37)
url38='https://histock.tw/stock/' + str(C38)
url39='https://histock.tw/stock/' + str(C39)
url40='https://histock.tw/stock/' + str(C40)
url41='https://histock.tw/stock/' + str(C41)
url42='https://histock.tw/stock/' + str(C42)
url43='https://histock.tw/stock/' + str(C43)
url44='https://histock.tw/stock/' + str(C44)
url45='https://histock.tw/stock/' + str(C45)
url46='https://histock.tw/stock/' + str(C46)
url47='https://histock.tw/stock/' + str(C47)
url48='https://histock.tw/stock/' + str(C48)
url49='https://histock.tw/stock/' + str(C49)
url50='https://histock.tw/stock/' + str(C50)

response1 =requests.get(url1)
response2=requests.get(url2)
response3=requests.get(url3)
response4=requests.get(url4)
response5=requests.get(url5)
response6=requests.get(url6)
response7=requests.get(url7)
response8=requests.get(url8)
response9=requests.get(url9)
response10=requests.get(url10)
response11=requests.get(url11)
response12=requests.get(url12)
response13=requests.get(url13)
response14=requests.get(url14)
response15=requests.get(url15)
response16=requests.get(url16)
response17=requests.get(url17)
response18=requests.get(url18)
response19=requests.get(url19)
response20=requests.get(url20)
response21=requests.get(url21)
response22=requests.get(url22)
response23=requests.get(url23)
response24=requests.get(url24)
response25=requests.get(url25)
response26=requests.get(url26)
response27=requests.get(url27)
response28=requests.get(url28)
response29=requests.get(url29)
response30=requests.get(url30)
response31=requests.get(url31)
response32=requests.get(url32)
response33=requests.get(url33)
response34=requests.get(url34)
response35=requests.get(url35)
response36=requests.get(url36)
response37=requests.get(url37)
response38=requests.get(url38)
response39=requests.get(url39)
response40=requests.get(url40)
response41=requests.get(url41)
response42=requests.get(url42)
response43=requests.get(url43)
response44=requests.get(url44)
response45=requests.get(url45)
response46=requests.get(url46)
response47=requests.get(url47)
response48=requests.get(url48)
response49=requests.get(url49)
response50=requests.get(url50)

root1=bs4.BeautifulSoup(response1.text, "html.parser")
root2=bs4.BeautifulSoup(response2.text, "html.parser")
root3=bs4.BeautifulSoup(response3.text, "html.parser")
root4=bs4.BeautifulSoup(response4.text, "html.parser")
root5=bs4.BeautifulSoup(response5.text, "html.parser")
root6=bs4.BeautifulSoup(response6.text, "html.parser")
root7=bs4.BeautifulSoup(response7.text, "html.parser")
root8=bs4.BeautifulSoup(response8.text, "html.parser")
root9=bs4.BeautifulSoup(response9.text, "html.parser")
root10=bs4.BeautifulSoup(response10.text, "html.parser")
root11=bs4.BeautifulSoup(response11.text, "html.parser")
root12=bs4.BeautifulSoup(response12.text, "html.parser")
root13=bs4.BeautifulSoup(response13.text, "html.parser")
root14=bs4.BeautifulSoup(response14.text, "html.parser")
root15=bs4.BeautifulSoup(response15.text, "html.parser")
root16=bs4.BeautifulSoup(response16.text, "html.parser")
root17=bs4.BeautifulSoup(response17.text, "html.parser")
root18=bs4.BeautifulSoup(response18.text, "html.parser")
root19=bs4.BeautifulSoup(response19.text, "html.parser")
root20=bs4.BeautifulSoup(response20.text, "html.parser")
root21=bs4.BeautifulSoup(response21.text, "html.parser")
root22=bs4.BeautifulSoup(response22.text, "html.parser")
root23=bs4.BeautifulSoup(response23.text, "html.parser")
root24=bs4.BeautifulSoup(response24.text, "html.parser")
root25=bs4.BeautifulSoup(response25.text, "html.parser")
root26=bs4.BeautifulSoup(response26.text, "html.parser")
root27=bs4.BeautifulSoup(response27.text, "html.parser")
root28=bs4.BeautifulSoup(response28.text, "html.parser")
root29=bs4.BeautifulSoup(response29.text, "html.parser")
root30=bs4.BeautifulSoup(response30.text, "html.parser")
root31=bs4.BeautifulSoup(response31.text, "html.parser")
root32=bs4.BeautifulSoup(response32.text, "html.parser")
root33=bs4.BeautifulSoup(response33.text, "html.parser")
root34=bs4.BeautifulSoup(response34.text, "html.parser")
root35=bs4.BeautifulSoup(response35.text, "html.parser")
root36=bs4.BeautifulSoup(response36.text, "html.parser")
root37=bs4.BeautifulSoup(response37.text, "html.parser")
root38=bs4.BeautifulSoup(response38.text, "html.parser")
root39=bs4.BeautifulSoup(response39.text, "html.parser")
root40=bs4.BeautifulSoup(response40.text, "html.parser")
root41=bs4.BeautifulSoup(response41.text, "html.parser")
root42=bs4.BeautifulSoup(response42.text, "html.parser")
root43=bs4.BeautifulSoup(response43.text, "html.parser")
root44=bs4.BeautifulSoup(response44.text, "html.parser")
root45=bs4.BeautifulSoup(response45.text, "html.parser")
root46=bs4.BeautifulSoup(response46.text, "html.parser")
root47=bs4.BeautifulSoup(response47.text, "html.parser")
root48=bs4.BeautifulSoup(response48.text, "html.parser")
root49=bs4.BeautifulSoup(response49.text, "html.parser")
root50=bs4.BeautifulSoup(response50.text, "html.parser")

E1=root1.find("span", id="Price1_lbTPrice")
E2=root2.find("span", id="Price1_lbTPrice")
E3=root3.find("span", id="Price1_lbTPrice")
E4=root4.find("span", id="Price1_lbTPrice")
E5=root5.find("span", id="Price1_lbTPrice")
E6=root6.find("span", id="Price1_lbTPrice")
E7=root7.find("span", id="Price1_lbTPrice")
E8=root8.find("span", id="Price1_lbTPrice")
E9=root9.find("span", id="Price1_lbTPrice")
E10=root10.find("span", id="Price1_lbTPrice")
E11=root11.find("span", id="Price1_lbTPrice")
E12=root12.find("span", id="Price1_lbTPrice")
E13=root13.find("span", id="Price1_lbTPrice")
E14=root14.find("span", id="Price1_lbTPrice")
E15=root15.find("span", id="Price1_lbTPrice")
E16=root16.find("span", id="Price1_lbTPrice")
E17=root17.find("span", id="Price1_lbTPrice")
E18=root18.find("span", id="Price1_lbTPrice")
E19=root19.find("span", id="Price1_lbTPrice")
E20=root20.find("span", id="Price1_lbTPrice")
E21=root21.find("span", id="Price1_lbTPrice")
E22=root22.find("span", id="Price1_lbTPrice")
E23=root23.find("span", id="Price1_lbTPrice")
E24=root24.find("span", id="Price1_lbTPrice")
E25=root25.find("span", id="Price1_lbTPrice")
E26=root26.find("span", id="Price1_lbTPrice")
E27=root27.find("span", id="Price1_lbTPrice")
E28=root28.find("span", id="Price1_lbTPrice")
E29=root29.find("span", id="Price1_lbTPrice")
E30=root30.find("span", id="Price1_lbTPrice")
E31=root31.find("span", id="Price1_lbTPrice")
E32=root32.find("span", id="Price1_lbTPrice")
E33=root33.find("span", id="Price1_lbTPrice")
E34=root34.find("span", id="Price1_lbTPrice")
E35=root35.find("span", id="Price1_lbTPrice")
E36=root36.find("span", id="Price1_lbTPrice")
E37=root37.find("span", id="Price1_lbTPrice")
E38=root38.find("span", id="Price1_lbTPrice")
E39=root39.find("span", id="Price1_lbTPrice")
E40=root40.find("span", id="Price1_lbTPrice")
E41=root41.find("span", id="Price1_lbTPrice")
E42=root42.find("span", id="Price1_lbTPrice")
E43=root43.find("span", id="Price1_lbTPrice")
E44=root44.find("span", id="Price1_lbTPrice")
E45=root45.find("span", id="Price1_lbTPrice")
E46=root46.find("span", id="Price1_lbTPrice")
E47=root47.find("span", id="Price1_lbTPrice")
E48=root48.find("span", id="Price1_lbTPrice")
E49=root49.find("span", id="Price1_lbTPrice")
E50=root50.find("span", id="Price1_lbTPrice")

#股票的股數可以當證券API的參數，因為股數必須為整數，所以四捨五入

D1=round (B1/float(E1.string),0)
D1=round (B1/float(E1.string),0)
D2=round (B2/float(E2.string),0)
D3=round (B3/float(E3.string),0)
D4=round (B4/float(E4.string),0)
D5=round (B5/float(E5.string),0)
D6=round (B6/float(E6.string),0)
D7=round (B7/float(E7.string),0)
D8=round (B8/float(E8.string),0)
D9=round (B9/float(E9.string),0)
D10=round (B10/float(E10.string),0)
D11=round (B11/float(E11.string),0)
D12=round (B12/float(E12.string),0)
D13=round (B13/float(E13.string),0)
D14=round (B14/float(E14.string),0)
D15=round (B15/float(E15.string),0)
D16=round (B16/float(E16.string),0)
D17=round (B17/float(E17.string),0)
D18=round (B18/float(E18.string),0)
D19=round (B19/float(E19.string),0)
D20=round (B20/float(E20.string),0)
D21=round (B21/float(E21.string),0)
D22=round (B22/float(E22.string),0)
D23=round (B23/float(E23.string),0)
D24=round (B24/float(E24.string),0)
D25=round (B25/float(E25.string),0)
D26=round (B26/float(E26.string),0)
D27=round (B27/float(E27.string),0)
D28=round (B28/float(E28.string),0)
D29=round (B29/float(E29.string),0)
D30=round (B30/float(E30.string),0)
D31=round (B31/float(E31.string),0)
D32=round (B32/float(E32.string),0)
D33=round (B33/float(E33.string),0)
D34=round (B34/float(E34.string),0)
D35=round (B35/float(E35.string),0)
D36=round (B36/float(E36.string),0)
D37=round (B37/float(E37.string),0)
D38=round (B38/float(E38.string),0)
D39=round (B39/float(E39.string),0)
D40=round (B40/float(E40.string),0)
D41=round (B41/float(E41.string),0)
D42=round (B42/float(E42.string),0)
D43=round (B43/float(E43.string),0)
D44=round (B44/float(E44.string),0)
D45=round (B45/float(E45.string),0)
D46=round (B46/float(E46.string),0)
D47=round (B47/float(E47.string),0)
D48=round (B48/float(E48.string),0)
D49=round (B49/float(E49.string),0)
D50=round (B50/float(E50.string),0)

#最後投資四捨五入，是為了呈現比較乾淨，計算時越接近真實值越好就沒四捨五入
print('1','股票代號',C1,F1,'股價',E1.string,'購買股數',D1,'投資金額',round(B1,0))
print('2','股票代號',C2,F2,'股價',E2.string,'購買股數',D2,'投資金額',round(B2,0))
print('3','股票代號',C3,F3,'股價',E3.string,'購買股數',D3,'投資金額',round(B3,0))
print('4','股票代號',C4,F4,'股價',E4.string,'購買股數',D4,'投資金額',round(B4,0))
print('5','股票代號',C5,F5,'股價',E5.string,'購買股數',D5,'投資金額',round(B5,0))
print('6','股票代號',C6,F6,'股價',E6.string,'購買股數',D6,'投資金額',round(B6,0))
print('7','股票代號',C7,F7,'股價',E7.string,'購買股數',D7,'投資金額',round(B7,0))
print('8','股票代號',C8,F8,'股價',E8.string,'購買股數',D8,'投資金額',round(B8,0))
print('9','股票代號',C9,F9,'股價',E9.string,'購買股數',D9,'投資金額',round(B9,0))
print('10','股票代號',C10,F10,'股價',E10.string,'購買股數',D10,'投資金額',round(B10,0))
print('11','股票代號',C11,F11,'股價',E11.string,'購買股數',D11,'投資金額',round(B11,0))
print('12','股票代號',C12,F12,'股價',E12.string,'購買股數',D12,'投資金額',round(B12,0))
print('13','股票代號',C13,F13,'股價',E13.string,'購買股數',D13,'投資金額',round(B13,0))
print('14','股票代號',C14,F14,'股價',E14.string,'購買股數',D14,'投資金額',round(B14,0))
print('15','股票代號',C15,F15,'股價',E15.string,'購買股數',D15,'投資金額',round(B15,0))
print('16','股票代號',C16,F16,'股價',E16.string,'購買股數',D16,'投資金額',round(B16,0))
print('17','股票代號',C17,F17,'股價',E17.string,'購買股數',D17,'投資金額',round(B17,0))
print('18','股票代號',C18,F18,'股價',E18.string,'購買股數',D18,'投資金額',round(B18,0))
print('19','股票代號',C19,F19,'股價',E19.string,'購買股數',D19,'投資金額',round(B19,0))
print('20','股票代號',C20,F20,'股價',E20.string,'購買股數',D20,'投資金額',round(B20,0))
print('21','股票代號',C21,F21,'股價',E21.string,'購買股數',D21,'投資金額',round(B21,0))
print('22','股票代號',C22,F22,'股價',E22.string,'購買股數',D22,'投資金額',round(B22,0))
print('23','股票代號',C23,F23,'股價',E23.string,'購買股數',D23,'投資金額',round(B23,0))
print('24','股票代號',C24,F24,'股價',E24.string,'購買股數',D24,'投資金額',round(B24,0))
print('25','股票代號',C25,F25,'股價',E25.string,'購買股數',D25,'投資金額',round(B25,0))
print('26','股票代號',C26,F26,'股價',E26.string,'購買股數',D26,'投資金額',round(B26,0))
print('27','股票代號',C27,F27,'股價',E27.string,'購買股數',D27,'投資金額',round(B27,0))
print('28','股票代號',C28,F28,'股價',E28.string,'購買股數',D28,'投資金額',round(B28,0))
print('29','股票代號',C29,F29,'股價',E29.string,'購買股數',D29,'投資金額',round(B29,0))
print('30','股票代號',C30,F30,'股價',E30.string,'購買股數',D30,'投資金額',round(B30,0))
print('31','股票代號',C31,F31,'股價',E31.string,'購買股數',D31,'投資金額',round(B31,0))
print('32','股票代號',C32,F32,'股價',E32.string,'購買股數',D32,'投資金額',round(B32,0))
print('33','股票代號',C33,F33,'股價',E33.string,'購買股數',D33,'投資金額',round(B33,0))
print('34','股票代號',C34,F34,'股價',E34.string,'購買股數',D34,'投資金額',round(B34,0))
print('35','股票代號',C35,F35,'股價',E35.string,'購買股數',D35,'投資金額',round(B35,0))
print('36','股票代號',C36,F36,'股價',E36.string,'購買股數',D36,'投資金額',round(B36,0))
print('37','股票代號',C37,F37,'股價',E37.string,'購買股數',D37,'投資金額',round(B37,0))
print('38','股票代號',C38,F38,'股價',E38.string,'購買股數',D38,'投資金額',round(B38,0))
print('39','股票代號',C39,F39,'股價',E39.string,'購買股數',D39,'投資金額',round(B39,0))
print('40','股票代號',C40,F40,'股價',E40.string,'購買股數',D40,'投資金額',round(B40,0))
print('41','股票代號',C41,F41,'股價',E41.string,'購買股數',D41,'投資金額',round(B41,0))
print('42','股票代號',C42,F42,'股價',E42.string,'購買股數',D42,'投資金額',round(B42,0))
print('43','股票代號',C43,F43,'股價',E43.string,'購買股數',D43,'投資金額',round(B43,0))
print('44','股票代號',C44,F44,'股價',E44.string,'購買股數',D44,'投資金額',round(B44,0))
print('45','股票代號',C45,F45,'股價',E45.string,'購買股數',D45,'投資金額',round(B45,0))
print('46','股票代號',C46,F46,'股價',E46.string,'購買股數',D46,'投資金額',round(B46,0))
print('47','股票代號',C47,F47,'股價',E47.string,'購買股數',D47,'投資金額',round(B47,0))
print('48','股票代號',C48,F48,'股價',E48.string,'購買股數',D48,'投資金額',round(B48,0))
print('49','股票代號',C49,F49,'股價',E49.string,'購買股數',D49,'投資金額',round(B49,0))
print('50','股票代號',C50,F50,'股價',E50.string,'購買股數',D50,'投資金額',round(B50,0))

#如果把API程式碼補上就可以一鍵下單一個投資組合，不用一個一個慢慢按慢慢輸入
``````
echochio iT邦高手 1 級 ‧ 2020-06-10 08:55:03 檢舉

Billour iT邦新手 5 級 ‧ 2020-06-10 14:49:13 檢舉

### 6 個回答

3
listennn08
iT邦高手 7 級 ‧ 2020-06-10 11:47:42

``````import pandas as pd
import numpy as np
from requests_html import HTMLSession

ss = HTMLSession()

Money=1000000

df = pd.DataFrame(df[0])
# column title 等於 0, 1, 2, 3 才用
df.columns = np.array(df[:1])[0]
df = df.drop([0])
# ^^^^^
MarketValue = np.array(df[:50]['市值佔大盤比重'].str.rstrip('%').astype('float'))/100
SumValue = np.sum(MarketValue)
F = np.array(df[:50]['名稱'])
B = A * Money
C = np.array(df[:50]['代號'].astype('str'))
stockUrl = 'https://histock.tw/stock/'
E, D = [], []
# 輸出沒有要用 dataframe 可以不用
name = ["{}-{}".format(C[i], item) for i, item in enumerate(F)]
columns = ["股票代號", "股價", "購買股數", "投資金額"]
# ^^^^
for i in range(0, 50):
res = float(ss.get(stockUrl+C[i]).html.find("span#Price1_lbTPrice")[0].text)
E.append(res)
D.append(round(B[i] / E[i],0))
# print("{}.\t股票代號: {}-{},\t股價: {},\t購買股數: {},\t投資金額: {}".format(i+1, C[i], F[i], E[i], D[i], round(B[i], 0) ))

# 輸出沒有要用 dataframe 可以不用
res_df = pd.DataFrame(np.array(np.transpose([name, E, D, np.round(B, 0)])), columns=columns)
res_df.index +=1
print(res_df)
``````
Alien iT邦新手 5 級 ‧ 2020-06-10 18:08:52 檢舉

colunm title應該是要0123

clash110502

numpy 基礎陣列運算還略懂
pandas 太廣泛了還有很多要學的

colunm title應該是要0123

``````# 我這個程式碼是因為印出來發現抓不到 column key 然後 index 0 是 key 才這樣寫 因為在 online complier 裡面並沒有出現 0, 1, 2, 3
# colunm title 等於 0, 1, 2, 3 才用
df.columns = np.array(df[:1])[0]
# 所以把 index 0 當成 column key ^^^
df = df.drop([0])
# 然後刪掉 index 0 ^^^
# ^^^^^
``````

Alien iT邦新手 5 級 ‧ 2020-06-11 01:52:43 檢舉

``````import pandas as pd
import numpy as np
from requests_html import HTMLSession

ss = HTMLSession()

Money=1000000

df = pd.DataFrame(df[0])
# colunm title 等於 0, 1, 2, 3 才用
#df.columns = np.array(df[:1])[0]
#df = df.drop([0])
# ^^^^^
MarketValue = np.array(df[:50]['市值佔大盤比重'].str.rstrip('%').astype('float'))/100
SumValue = np.sum(MarketValue)
F = np.array(df[:50]['名稱'])
B = A * Money
C = np.array(df[:50]['代號'].astype('str'))
stockUrl = 'https://histock.tw/stock/'
E, D = [], []
# 輸出沒有要用 dataframe 可以不用
#name = ["{}-{}".format(C[i], item) for i, item in enumerate(F)]
columns = ["股票代號","股票名稱", "股價", "購買股數", "投資金額"]
# ^^^^
for i in range(0, 50):
res = float(ss.get(stockUrl+C[i]).html.find("span#Price1_lbTPrice")[0].text)
E.append(res)
D.append(round(B[i] / E[i],0))
# print("{}.\t股票代號: {}-{},\t股價: {},\t購買股數: {},\t投資金額: {}".format(i+1, C[i], F[i], E[i], D[i], round(B[i], 0) ))

# 輸出沒有要用 dataframe 可以不用
res_df = pd.DataFrame(np.array(np.transpose([C,F, E, D, np.round(B, 0)])), columns=columns)
res_df.index +=1
print(res_df)
``````

``````    股票代號   股票名稱     股價 購買股數    投資金額
1   2330    台積電  322.5  899  290038
2   2317     鴻海   79.9  722   57659
3   6505    台塑化   96.3  536   51647
4   2412    中華電    113  357   40353
5   1301     台塑   89.4  346   30938
6   1326     台化   77.1  388   29917
7   2882    國泰金  42.35  703   29792
8   1303     南亞   67.4  427   28782
9   2881    富邦金   44.6  545   24293
10  3008    大立光   4400    5   23030
11  1216     統一   73.7  272   20038
12  2891    中信金   21.1  921   19427
13  2002     中鋼   21.2  865   18331
14  3045    台灣大  108.5  168   18213
15  2454    聯發科    500   36   17997
16  2886    兆豐金   32.1  533   17104
17  2912    統一超  298.5   55   16427
18  2308    台達電  160.5  102   16304
19  3711  日月光投控     68  192   13083
20  2892    第一金   23.5  518   12173
21  4904     遠傳   68.5  170   11634
22  5880    合庫金  21.25  514   10928
23  2884    玉山金  28.35  385   10922
24  2880    華南金   20.4  488    9952
25  2474     可成  224.5   42    9502
26  2382     廣達   69.8  133    9273
27  2408    南亞科     64  143    9135
28  2885    元大金   18.5  481    8904
29  1101     台泥     44  193    8496
30  2801     彰銀  20.25  416    8415
31  2357     華碩    225   35    7909
32  2395     研華    294   26    7683
33  2327     國巨  394.5   19    7448
34  1402    遠東新   28.7  258    7400
35  2883    開發金   9.47  771    7299
36  2303     聯電   16.6  420    6978
37  2887    台新金   13.7  502    6881
38  4938     和碩     67  100    6687
39  2105     正新     36  183    6587
40  9910     豐泰    190   34    6492
41  2207    和泰車    684    9    6176
42  2888    新光金   9.01  684    6160
43  5871  中租-KY  129.5   46    5996
44  2409     友達   9.58  623    5970
45  2890    永豐金  12.35  468    5781
46  2823     中壽   22.8  249    5675
47  1102     亞泥   44.8  120    5361
48  1476     儒鴻  349.5   15    5079
49  3481     群創   8.04  626    5031
50  9904     寶成  30.25  155    4700
``````
4

iT邦大師 1 級 ‧ 2020-06-09 21:41:12

ckp6250 iT邦好手 1 級 ‧ 2020-06-09 21:49:38 檢舉

汝有田舍翁，家貲殷盛，而累世不識之无。一歲，聘楚士訓其子。楚士始訓之搦管臨朱，書一畫， 訓曰「一」字；書二畫，訓曰「二」字；書三畫，訓曰「三」字。其子輒欣欣然，擲筆歸，告其父 曰：『兒得矣！兒得矣！可無煩先生，重費館穀也。請謝去。』

其父喜，從之，具幣謝遣楚士。 踰時，其父擬徵召姻友萬氏者飲，令子晨起治狀，久之不成。父趣之。其子恚曰：「天下姓字夥矣，奈何姓萬？自晨起至今，才完成五百畫也。」

Alien iT邦新手 5 級 ‧ 2020-06-09 22:03:44 檢舉

froce iT邦大師 1 級 ‧ 2020-06-09 22:16:50 檢舉

https://ithelp.ithome.com.tw/questions/10196084

8

iT邦研究生 5 級 ‧ 2020-06-09 21:47:01

``````MarketValue1 = float(zz.at[0, '市值佔大盤比重'].strip('%'))
Value1=MarketValue1/100

MarketValue2 = float(zz.at[1, '市值佔大盤比重'].strip('%'))
Value2=MarketValue2/100

MarketValue3 = float(zz.at[2, '市值佔大盤比重'].strip('%'))
Value3=MarketValue3/100

MarketValue4 = float(zz.at[3, '市值佔大盤比重'].strip('%'))
Value4=MarketValue4/100
(...重複50個)
``````

``````MarketValue = [0] * 50 #宣告大小為50的陣列
Value = [0] * 50 #宣告大小為50的陣列
for i in range(50): #重複做50次，i的值從0~49在跑
MarketValue[i] =  float(zz.at[i, '市值佔大盤比重'].strip('%'))
Value[i] = MarketValue[i]/100
``````

• list是用來存大量資料的結構
• for是用來做重複事情的邏輯

Alien iT邦新手 5 級 ‧ 2020-06-09 22:22:33 檢舉

list(列表，或陣列)

``````C1=zz.at[0, '代號']
C2=zz.at[1, '代號']
C3=zz.at[2, '代號']
C4=zz.at[3, '代號']
C5=zz.at[4, '代號']
C6=zz.at[5, '代號']
C7=zz.at[6, '代號']
C8=zz.at[7, '代號']
...
(...重複50個)
``````

``````C = [0] * 50 #宣告大小為50的陣列
for i in range(50): #重複做50次，i的值從0~49在跑
C[i] = zz.at[i, '代號']
``````

(你可以感受一下，為何我說改的邏輯都類似?)

(我沒有說最佳解答一定要給我哦，

(我是用anaconda的spyder來寫python, panda模組自動安裝好了)

Alien iT邦新手 5 級 ‧ 2020-06-10 00:14:58 檢舉

https://imgur.com/dwuXaQ5

<至於但想請教一下股票代號C1~C50

list(列表，或陣列)

C1~C50 D1~D50

Alien iT邦新手 5 級 ‧ 2020-06-10 01:09:06 檢舉

4
froce
iT邦大師 1 級 ‧ 2020-06-09 22:29:29

ㄜ...你應該先學list、什麼是list slice、pandas文件多看看。
pandas的思考模式你應該把他當資料庫/excel去思考，變動、查詢什麼的多用他裡面內建的，會比用迴圈快很多。

``````import pandas as pd

zz =pd.DataFrame(df[0])
print(zz['市值佔大盤比重'])

# 只需要這行，自己參詳吧。
zz['市值佔大盤比重'] =  zz['市值佔大盤比重'].str.rstrip('%').astype('float') / 100.0

print(zz['市值佔大盤比重'][:50])
``````

Alien iT邦新手 5 級 ‧ 2020-06-09 22:31:17 檢舉

Alien iT邦新手 5 級 ‧ 2020-06-09 22:42:07 檢舉

pandas跟NumPy的差別主要在哪?

froce iT邦大師 1 級 ‧ 2020-06-09 22:52:42 檢舉

numpy是注重在矩陣運算的部分，pandas比較像資料庫/excel。

pandas裡面也是以numpy作為基礎。

Alien iT邦新手 5 級 ‧ 2020-06-09 23:00:22 檢舉

3

iT邦大神 1 級 ‧ 2020-06-09 23:22:43

``````import pandas as pd
import requests
import bs4

Money=1000000

print(df[0])

zz =pd.DataFrame(df[0])

SumValue = 0.0
for x in range(0, 50):
MarketValue = float(zz.at[x, '市值佔大盤比重'].strip('%'))
SumValue = SumValue + MarketValue/100.0

arrStock = []
for x in range(0, 50):
oneStock = {}

MarketValue = float(zz.at[x, '市值佔大盤比重'].strip('%'))
oneStock['市值佔大盤比重'] = MarketValue/100
oneStock['F'] = zz.at[x,'NAME']
oneStock['B'] = Money * oneStock['A']
oneStock['C'] = zz.at[x, 'CODE']
url='https://histock.tw/stock/' + str(oneStock['C'])
response =requests.get(url)
root=bs4.BeautifulSoup(response.text, "html.parser")
oneStock['E']=root.find("span", id="Price1_lbTPrice")
oneStock['D']=round(oneStock['B']/oneStock['E'],0)

arrStock.append(oneStock)
print(oneStock)   #用迴圈一筆一筆印出來用這列

print(arrStock)   #一次全部印出來用這列
``````
Alien iT邦新手 5 級 ‧ 2020-06-10 00:30:13 檢舉

print arrStock改print (arrStock)

Alien iT邦新手 5 級 ‧ 2020-06-11 01:44:35 檢舉

``````import pandas as pd
import requests
import bs4

Money=1000000

print(df[0])

zz =pd.DataFrame(df[0])

SumValue = 0.0
for x in range(0, 50):
MarketValue = float(zz.at[x, '市值佔大盤比重'].strip('%'))
SumValue = SumValue + MarketValue/100.0

arrStock = []
for x in range(0, 50):
oneStock = {}

MarketValue = float(zz.at[x, '市值佔大盤比重'].strip('%'))
oneStock['市值佔大盤比重'] = MarketValue/100
oneStock['F'] = zz.at[x,'名稱']
oneStock['B'] = Money * oneStock['A']
oneStock['C'] = zz.at[x, '代號']
url='https://histock.tw/stock/' + str(oneStock['C'])
response =requests.get(url)
root=bs4.BeautifulSoup(response.text, "html.parser")
oneStock['E']=root.find("span", id="Price1_lbTPrice")
oneStock['D']=round(oneStock['B']/float(oneStock['E'].string),0)

arrStock.append(oneStock)
#print(oneStock)   #用迴圈一筆一筆印出來用這列

print(arrStock)   #一次全部印出來用這列
``````

``````     排行    代號     名稱   市值佔大盤比重
0      1  2330    台積電  21.1929%
1      2  2317     鴻海   4.2131%
2      3  6505    台塑化   3.7738%
3      4  2412    中華電   2.9486%
4      5  1301     台塑   2.2606%
..   ...   ...    ...       ...
448  449  2107     厚生   0.0204%
449  450  4763  材料-KY   0.0204%
450  451  2910     統領   0.0203%
451  452  2472    立隆電   0.0203%
452  453  2939  凱羿-KY   0.0202%

[453 rows x 4 columns]
[{'市值佔大盤比重': 0.211929, 'A': 290037.9639082845, 'F': '台積電', 'B': 290037963908.2845, 'C': 2330, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">322.5</span></span>, 'D': 899342524.0}, {'市值佔大盤比重': 0.042131, 'A': 57658.88319871247, 'F': '鴻海', 'B': 57658883198.71247, 'C': 2317, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">79.9</span></span>, 'D': 721638088.0}, {'市值佔大盤比重': 0.037738, 'A': 51646.79058538869, 'F': '台塑化', 'B': 51646790585.388695, 'C': 6505, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">96.3</span></span>, 'D': 536311429.0}, {'市值佔大盤比重': 0.029486, 'A': 40353.417436026575, 'F': '中華電', 'B': 40353417436.02657, 'C': 2412, 'E': <span id="Price1_lbTPrice"><span>113.0</span></span>, 'D': 357109889.0}, {'市值佔大盤比重': 0.022606, 'A': 30937.71127174988, 'F': '台塑', 'B': 30937711271.749878, 'C': 1301, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">89.4</span></span>, 'D': 346059410.0}, {'市值佔大盤比重': 0.02186, 'A': 29916.764062658247, 'F': '台化', 'B': 29916764062.658245, 'C': 1326, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">77.1</span></span>, 'D': 388025474.0}, {'市值佔大盤比重': 0.021768999999999997, 'A': 29792.224925892373, 'F': '國泰金', 'B': 29792224925.892372, 'C': 2882, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">42.35</span></span>, 'D': 703476385.0}, {'市值佔大盤比重': 0.021031, 'A': 28782.226212340604, 'F': '南亞', 'B': 28782226212.340603, 'C': 1303, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">67.4</span></span>, 'D': 427035997.0}, {'市值佔大盤比重': 0.017751, 'A': 24293.34304099938, 'F': '富邦金', 'B': 24293343040.999382, 'C': 2881, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">44.60</span></span>, 'D': 544693790.0}, {'市值佔大盤比重': 0.016828, 'A': 23030.160368088425, 'F': '大立光', 'B': 23030160368.088425, 'C': 3008, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">4400</span></span>, 'D': 5234127.0}, {'市值佔大盤比重': 0.014641999999999999, 'A': 20038.4839618226, 'F': '統一', 'B': 20038483961.8226, 'C': 1216, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">73.7</span></span>, 'D': 271892591.0}, {'市值佔大盤比重': 0.014195, 'A': 19426.73677353311, 'F': '中信金', 'B': 19426736773.53311, 'C': 2891, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">21.10</span></span>, 'D': 920698425.0}, {'市值佔大盤比重': 0.013394, 'A': 18330.518657604964, 'F': '中鋼', 'B': 18330518657.604965, 'C': 2002, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">21.20</span></span>, 'D': 864647106.0}, {'市值佔大盤比重': 0.013308, 'A': 18212.822330551506, 'F': '台灣大', 'B': 18212822330.551506, 'C': 3045, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">108.5</span></span>, 'D': 167860114.0}, {'市值佔大盤比重': 0.01315, 'A': 17996.58954363934, 'F': '聯發科', 'B': 17996589543.63934, 'C': 2454, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">500.0</span></span>, 'D': 35993179.0}, {'市值佔大盤比重': 0.012498, 'A': 17104.287157141025, 'F': '兆豐金', 'B': 17104287157.141026, 'C': 2886, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">32.10</span></span>, 'D': 532843837.0}, {'市值佔大盤比重': 0.012003, 'A': 16426.848995612392, 'F': '統一超', 'B': 16426848995.612392, 'C': 2912, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">298.5</span></span>, 'D': 55031320.0}, {'市值佔大盤比重': 0.011913, 'A': 16303.678420789007, 'F': '台達電', 'B': 16303678420.789007, 'C': 2308, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">160.5</span></span>, 'D': 101580551.0}, {'市值佔大盤比重': 0.009559999999999999, 'A': 13083.452170128674, 'F': '日月光投控', 'B': 13083452170.128674, 'C': 3711, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">68.0</span></span>, 'D': 192403708.0}, {'市值佔大盤比重': 0.008895, 'A': 12173.358478378093, 'F': '第一金', 'B': 12173358478.378094, 'C': 2892, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">23.50</span></span>, 'D': 518015254.0}, {'市值佔大盤比重': 0.008501, 'A': 11634.145073040152, 'F': '遠傳', 'B': 11634145073.040152, 'C': 4904, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">68.5</span></span>, 'D': 169841534.0}, {'市值佔大盤比重': 0.007984999999999999, 'A': 10927.967110719399, 'F': '合庫金', 'B': 10927967110.719398, 'C': 5880, 'E': <span id="Price1_lbTPrice"><span>21.25</span></span>, 'D': 514257276.0}, {'市值佔大盤比重': 0.007981, 'A': 10922.492862949473, 'F': '玉山金', 'B': 10922492862.949474, 'C': 2884, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">28.35</span></span>, 'D': 385273117.0}, {'市值佔大盤比重': 0.007272, 'A': 9952.182445729677, 'F': '華南金', 'B': 9952182445.729677, 'C': 2880, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">20.40</span></span>, 'D': 487852081.0}, {'市值佔大盤比重': 0.006943, 'A': 9501.925566653075, 'F': '可成', 'B': 9501925566.653076, 'C': 2474, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">224.5</span></span>, 'D': 42324835.0}, {'市值佔大盤比重': 0.006776, 'A': 9273.375722258568, 'F': '廣達', 'B': 9273375722.258568, 'C': 2382, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">69.8</span></span>, 'D': 132856386.0}, {'市值佔大盤比重': 0.0066749999999999995, 'A': 9135.150966067877, 'F': '南亞科', 'B': 9135150966.067877, 'C': 2408, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">64.0</span></span>, 'D': 142736734.0}, {'市值佔大盤比重': 0.006506, 'A': 8903.863997788405, 'F': '元大金', 'B': 8903863997.788404, 'C': 2885, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">18.50</span></span>, 'D': 481289946.0}, {'市值佔大盤比重': 0.006208, 'A': 8496.032538928746, 'F': '台泥', 'B': 8496032538.928746, 'C': 1101, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">44.00</span></span>, 'D': 193091649.0}, {'市值佔大盤比重': 0.006149, 'A': 8415.287384322304, 'F': '彰銀', 'B': 8415287384.322304, 'C': 2801, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">20.25</span></span>, 'D': 415569747.0}, {'市值佔大盤比重': 0.005778999999999999, 'A': 7908.919465603934, 'F': '華碩', 'B': 7908919465.603934, 'C': 2357, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">225.0</span></span>, 'D': 35150753.0}, {'市值佔大盤比重': 0.005614, 'A': 7683.106745094391, 'F': '研華', 'B': 7683106745.094391, 'C': 2395, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">294.0</span></span>, 'D': 26133016.0}, {'市值佔大盤比重': 0.005442, 'A': 7447.714090987473, 'F': '國巨', 'B': 7447714090.9874735, 'C': 2327, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">394.5</span></span>, 'D': 18878870.0}, {'市值佔大盤比重': 0.0054069999999999995, 'A': 7399.8144230006, 'F': '遠東新', 'B': 7399814423.0006, 'C': 1402, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">28.70</span></span>, 'D': 257833255.0}, {'市值佔大盤比重': 0.005333, 'A': 7298.540839256927, 'F': '開發金', 'B': 7298540839.2569275, 'C': 2883, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">9.47</span></span>, 'D': 770701250.0}, {'市值佔大盤比重': 0.005099, 'A': 6978.29734471612, 'F': '聯電', 'B': 6978297344.716121, 'C': 2303, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">16.60</span></span>, 'D': 420379358.0}, {'市值佔大盤比重': 0.005028, 'A': 6881.129446799893, 'F': '台新金', 'B': 6881129446.799893, 'C': 2887, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">13.70</span></span>, 'D': 502272222.0}, {'市值佔大盤比重': 0.004886, 'A': 6686.793650967438, 'F': '和碩', 'B': 6686793650.967439, 'C': 4938, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">67.0</span></span>, 'D': 99802890.0}, {'市值佔大盤比重': 0.0048130000000000004, 'A': 6586.888629166247, 'F': '正新', 'B': 6586888629.166246, 'C': 2105, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">36.00</span></span>, 'D': 182969129.0}, {'市值佔大盤比重': 0.004744, 'A': 6492.457855134983, 'F': '豐泰', 'B': 6492457855.134983, 'C': 9910, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">190.0</span></span>, 'D': 34170831.0}, {'市值佔大盤比重': 0.004513, 'A': 6176.320046421622, 'F': '和泰車', 'B': 6176320046.421621, 'C': 2207, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">684</span></span>, 'D': 9029708.0}, {'市值佔大盤比重': 0.004501, 'A': 6159.897303111837, 'F': '新光金', 'B': 6159897303.111836, 'C': 2888, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">9.01</span></span>, 'D': 683673397.0}, {'市值佔大盤比重': 0.0043809999999999995, 'A': 5995.669870013988, 'F': '中租-KY', 'B': 5995669870.013988, 'C': 5871, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">129.5</span></span>, 'D': 46298609.0}, {'市值佔大盤比重': 0.0043619999999999996, 'A': 5969.667193106828, 'F': '友達', 'B': 5969667193.106828, 'C': 2409, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">9.58</span></span>, 'D': 623138538.0}, {'市值佔大盤比重': 0.004224, 'A': 5780.805645044302, 'F': '永豐金', 'B': 5780805645.044302, 'C': 2890, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">12.35</span></span>, 'D': 468081429.0}, {'市值佔大盤比重': 0.0041470000000000005, 'A': 5675.426375473182, 'F': '中壽', 'B': 5675426375.473182, 'C': 2823, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">22.80</span></span>, 'D': 248922209.0}, {'市值佔大盤比重': 0.003917, 'A': 5360.657128702303, 'F': '亞泥', 'B': 5360657128.702304, 'C': 1102, 'E': <span id="Price1_lbTPrice"><span class="clr-gr">44.80</span></span>, 'D': 119657525.0}, {'市值佔大盤比重': 0.003711, 'A': 5078.733368550995, 'F': '儒鴻', 'B': 5078733368.550995, 'C': 1476, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">349.5</span></span>, 'D': 14531426.0}, {'市值佔大盤比重': 0.003676, 'A': 5030.833700564122, 'F': '群創', 'B': 5030833700.564122, 'C': 3481, 'E': <span id="Price1_lbTPrice"><span class="clr-rd">8.04</span></span>, 'D': 625725585.0}, {'市值佔大盤比重': 0.003434, 'A': 4699.641710483459, 'F': '寶成', 'B': 4699641710.483459, 'C': 9904, 'E': <span id="Price1_lbTPrice"><span>30.25</span></span>, 'D': 155360057.0}]
``````
0
ckp6250
iT邦好手 1 級 ‧ 2020-06-10 09:35:40

Alien iT邦新手 5 級 ‧ 2020-06-10 18:21:39 檢舉

ckp6250 iT邦好手 1 級 ‧ 2020-06-10 20:50:35 檢舉

clash110502

我的學習方法不見得很好，您參考看看。

每當我打算去學一項新東西時，我一定把市面上買得到的相關書籍都買齊，然後一頁一頁仔細去看去測試，因為每個作者寫法都不同，如果您學了10個作者的方法，其中總會有一個作者的寫法是您能吸收的，那入門就突破了。

其實，學程式最困難在於突破門檻，只要一跨過門檻，後面就海闊天空，進步神速了，但，最困難的也在於，您不知道誰可以帶您跨越門檻？這時，只好把所有作者都請回家，一個一個接觸，總會找得到。