Search this site
Embedded Files
Skip to main content
Skip to navigation
課程網頁
首頁
AI
EXCEL
健康與生活
工程數學
常微分方程
線性常係數
Fourier Series
Fourier Series Example
SLBVP
線性代數
Linear Algebra
基礎定義
線性轉換
rref
eigenvalue vector
Eig. Example 1
Eig. Example 2
Eig. Example 3
Eig. Property
SVD
python basics
SVD_APP
SVD預備定理
4 space
vectorSpace
row operation
DimRowColumnPF
座標轉換
相似轉換
相似對角化
OrthogonalM
symetricMatrix
EVD
正交對角化
聯立方程組之解
projection
Affine Transformation
LT Graph
Gram-Schmidt
EiApp
Principal Stress
應用電子學
電子學基礎
分壓定律
繼電器
4069反相器
光感測
Arduino
ATmega328
超音波感測
ESP8266
Arduino IDE 設定
AP webserver
Sta+SerialMonitor webserver
Sta+AP webserver
使用Ajax
EEPROM+OTA
OTA
EEPROM
OLED (128x64)
MQTT
ESP01DHT11MQTT
AutoConnect+OTA
RTC Clock
計組實驗
普通物理
資料探勘
dataCollecting
資料整理
存入資料庫與篩選資料
繪製K 線
機器學習
監督式學習
了解系統
供給需求
TA-LIB技術指標
資料轉換
買賣信號
課程網頁
首頁
AI
EXCEL
健康與生活
工程數學
常微分方程
線性常係數
Fourier Series
Fourier Series Example
SLBVP
線性代數
Linear Algebra
基礎定義
線性轉換
rref
eigenvalue vector
Eig. Example 1
Eig. Example 2
Eig. Example 3
Eig. Property
SVD
python basics
SVD_APP
SVD預備定理
4 space
vectorSpace
row operation
DimRowColumnPF
座標轉換
相似轉換
相似對角化
OrthogonalM
symetricMatrix
EVD
正交對角化
聯立方程組之解
projection
Affine Transformation
LT Graph
Gram-Schmidt
EiApp
Principal Stress
應用電子學
電子學基礎
分壓定律
繼電器
4069反相器
光感測
Arduino
ATmega328
超音波感測
ESP8266
Arduino IDE 設定
AP webserver
Sta+SerialMonitor webserver
Sta+AP webserver
使用Ajax
EEPROM+OTA
OTA
EEPROM
OLED (128x64)
MQTT
ESP01DHT11MQTT
AutoConnect+OTA
RTC Clock
計組實驗
普通物理
資料探勘
dataCollecting
資料整理
存入資料庫與篩選資料
繪製K 線
機器學習
監督式學習
了解系統
供給需求
TA-LIB技術指標
資料轉換
買賣信號
More
首頁
AI
EXCEL
健康與生活
工程數學
常微分方程
線性常係數
Fourier Series
Fourier Series Example
SLBVP
線性代數
Linear Algebra
基礎定義
線性轉換
rref
eigenvalue vector
Eig. Example 1
Eig. Example 2
Eig. Example 3
Eig. Property
SVD
python basics
SVD_APP
SVD預備定理
4 space
vectorSpace
row operation
DimRowColumnPF
座標轉換
相似轉換
相似對角化
OrthogonalM
symetricMatrix
EVD
正交對角化
聯立方程組之解
projection
Affine Transformation
LT Graph
Gram-Schmidt
EiApp
Principal Stress
應用電子學
電子學基礎
分壓定律
繼電器
4069反相器
光感測
Arduino
ATmega328
超音波感測
ESP8266
Arduino IDE 設定
AP webserver
Sta+SerialMonitor webserver
Sta+AP webserver
使用Ajax
EEPROM+OTA
OTA
EEPROM
OLED (128x64)
MQTT
ESP01DHT11MQTT
AutoConnect+OTA
RTC Clock
計組實驗
普通物理
資料探勘
dataCollecting
資料整理
存入資料庫與篩選資料
繪製K 線
機器學習
監督式學習
了解系統
供給需求
TA-LIB技術指標
資料轉換
買賣信號
存入資料庫與篩選資料
getDailyDataFinal1.ipynb (
link
)
建立資料庫與更新資料庫
#請先mount 你的Google Drive
import
pandas
as
pd
import
sqlite3
import
time
dataBase='/content/drive/My Drive/pyStock/stockData.db'
def
getDailyQuotation
(
date
):
import
pandas
as
pd
url=
'http://www.twse.com.tw/exchangeReport/MI_INDEX?response=html&date='
+date+
'&type=ALLBUT0999'
try
:
df = pd.read_html(url,match=
'每日收盤行情'
)[
0
]
except
:
return
None
if
df
is
not
None
:
nl=df.columns.nlevels
df.columns = df.columns.get_level_values(nl
-1
)
df.drop([
'證券名稱'
,
'漲跌(+/-)'
], inplace=
True
, axis=
1
)
df[
'日期'
] = pd.to_datetime(date)
df = df.set_index([
'證券代號'
,
'日期'
])
df = df.apply(pd.to_numeric, errors=
'coerce'
)
df.drop(df[df[
'收盤價'
].isnull()].index, inplace=
True
)
return
df
def
saveDailyQuotation
(
newDF
):
connection = sqlite3.connect(dataBase)
try
:
dbDF = pd.read_sql(
'select * from dailyQuotation'
, connection, parse_dates=[
'日期'
], index_col=[
'證券代號'
,
'日期'
])
except
:
dbDF = pd.DataFrame()
appendDF = dbDF.append(newDF, sort=
False
)
finalDF = appendDF.reset_index().drop_duplicates(subset=[
'證券代號'
,
'日期'
], keep=
'last'
).set_index([
'證券代號'
,
'日期'
]).sort_index()
finalDF.to_sql(
'dailyQuotation'
, connection, if_exists=
'replace'
)
connection.close()
def
updateDailyQuotation
(
start_date
,
end_date
):
newDF = pd.DataFrame()
for
date
in
pd.date_range(start_date, end_date):
df = getDailyQuotation(date.strftime(
'%Y%m%d'
))
if
df
is
not
None
:
newDF = newDF.append(df)
print
(
'{} complete'
.
format
(date.strftime(
'%Y%m%d'
)))
else
:
print
(
'{} not found'
.
format
(date.strftime(
'%Y%m%d'
)))
time.sleep(
15
)
saveDailyQuotation(newDF)
return
newDF
updateDailyQuotation(
'202
1
/
2
/
23
'
,
'202
1
/
2
/
26
'
)
篩選資料
dataBase='/content/drive/My Drive/pyStock/stockData.db'
connection = sqlite3.connect(
dataBase
)
try:
df_0050 = pd.read_sql('select * from dailyQuotation where [證券代號]="0050"', connection, parse_dates=['日期'], index_col=['證券代號', '日期'])
except:
df_0050 = pd.DataFrame()
connection.close()
df_0050
DB.Browser.for.SQLite-3.12.1-win64
官網(
link
)
從Yahoo取得股票行情
YahooStockData.ipynb(
share
)
Google Sites
Report abuse
Google Sites
Report abuse