PIXNET Logo登入

史坦利Stanley程式Maker的部落格

跳到主文

歡迎光臨史坦利Stanley程式Maker痞客邦的小天地

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 10月 02 週三 201909:51
  • 資料分析常用程式收集

(1) 一個基本的範例 擷取檔案且儲存至csv
from collections import OrderedDict
import requests
import pandas as pd
from bs4 import BeautifulSoup
class HTMLTableParser:
def get_html_tables_from_resp(self, html_text):
soup = BeautifulSoup(html_text, 'html.parser')
tables = soup.find_all('table')
return tables
def parse_html_table(self, table):
"""
<tr>
<th align="center" class="tblHead" nowrap="" rowspan="2">產業類別</th>
<th align="center" class="tblHead" nowrap="" rowspan="2">公司代號</th>
<th align="center" class="tblHead" nowrap="" rowspan="2">公司名稱</th>
<th align="center" class="tblHead" colspan="4" nowrap="">非擔任主管職務之<br/>全時員工資訊</th>
<th align="center" class="tblHead" colspan="2" nowrap="">同業公司資訊</th>
<th align="center" class="tblHead" colspan="4" nowrap="">薪資統計情形</th>
</tr>
<tr>
<th align="center" class="tblHead" nowrap="">員工薪資總額(仟元)</th>
<th align="center" class="tblHead" nowrap="">員工人數-加權平均(人)</th>
<th align="center" class="tblHead" nowrap="">員工薪資-平均數(仟元/人)</th>
<th align="center" class="tblHead" nowrap="">每股盈餘(元/股)</th>
<th align="center" class="tblHead" nowrap="">員工薪資-平均數(仟元/人)</th>
<th align="center" class="tblHead" nowrap="">平均每股盈餘(元/股)</th>
<th align="center" class="tblHead" nowrap="">非經理人之<br/>全時員工薪資<br/>平均數未達50萬元</th>
<th align="center" class="tblHead" nowrap="">公司EPS獲利表現較同業為佳<br/>,惟非經理人之全時員工<br/>薪資平均數低於同業水準</th>
<th align="center" class="tblHead" nowrap="">公司EPS較前一年度成長<br/>,惟非經理人之全時員工<br/>薪資平均數較前一年度減少</th>
<th align="center" class="tblHead" nowrap="">公司經營績效與員工薪酬<br/>之關聯性及合理性說明</th>
</tr>
<tr>
<td nowrap="" style="text-align:left !important;">資訊服務業</td>
<td nowrap="" style="text-align:left !important;">8416</td>
<td nowrap="" style="text-align:left !important;">實威</td>
<td nowrap="" style="text-align:right !important;"> 158,636 </td>
<td nowrap="" style="text-align:right !important;"> 186 </td>
<td nowrap="" style="text-align:right !important;"> 853 </td>
<td nowrap="" style="text-align:right !important;"> 9.69 </td>
<td nowrap="" style="text-align:right !important;"> 807 </td>
<td nowrap="" style="text-align:right !important;"> 1.20 </td>
<td nowrap="" style="text-align:right !important;"></td>
<td nowrap="" style="text-align:right !important;"></td>
<td nowrap="" style="text-align:right !important;"></td>
<td nowrap="" style="text-align:left !important;"><br/></td>
</tr>
"""
parsed_data = []
# Find number of rows and columns
# we also find the column titles if we can
table_row_tags = table.find_all('tr')
table_header_tags = table.find_all('th')
column_names = [table_header_tag.get_text() for key, table_header_tag in enumerate(table_header_tags) if key not in (3, 4, 5)]
column_names[7] = '同業公司{}'.format(column_names[7])
column_names[8] = '同業公司{}'.format(column_names[8])
tr_td_tags = [
[td_tag.get_text().strip() for td_tag in table_row.find_all('td')]
for table_row in table_row_tags if table_row.find_all('td')
]
parsed_data = [
OrderedDict({
column_names[index]: td_tag
for index, td_tag in enumerate(tr_td_tag)
})
for tr_td_tag in tr_td_tags
]
df = pd.DataFrame.from_dict(parsed_data)
return df
htlm_parser = HTMLTableParser()
payload = {
# 'encodeURIComponent': 1,
'step': 1,
'firstin': 1,
'TYPEK': 'sii', # sii 上市 / otc 上櫃
'RYEAR': 107,
'code': '',
}
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'}
resp = requests.post('https://mops.twse.com.tw/mops/web/ajax_t100sb15', data=payload, headers=headers, timeout=2)
html_tables = htlm_parser.get_html_tables_from_resp(resp.text)
df_table = htlm_parser.parse_html_table(html_tables[0])
df_table.to_csv('107_{}.csv'.format(payload['TYPEK']), index=False, encoding='utf-8')
print(df_table)
(繼續閱讀...)
文章標籤

stanley 發表在 痞客邦 留言(0) 人氣(38)

  • 個人分類:資料科學
▲top
  • 2月 22 週五 201910:29
  • 資料科學自我學習

「data science learning path」的圖片搜尋結果
 
數據科學(英語:data science),又稱資料科學,是一門利用數據學習知識的學科,其目標是通過從數據中提取出有價值的部分來生產數據產品[1]。它結合了諸多領域中的理論和技術,包括應用數學、統計、模式識別、機器學習、數據可視化、數據倉庫以及高性能計算。數據科學通過運用各種相關的數據來幫助非專業人士理解問題。 數據科學技術可以幫助我們如何正確的處理數據並協助我們在生物學、社會科學、人類學等領域進行研究調研。此外,數據科學也對商業競爭有極大的幫助。
(繼續閱讀...)
文章標籤

stanley 發表在 痞客邦 留言(0) 人氣(23)

  • 個人分類:資料科學
▲top
  • 11月 22 週四 201816:55
  • web app dash & plotly for iot data visualization

https://dash.plot.ly/  (user giude)
https://dash.plot.ly/?_ga=2.103650308.589841288.1542985557-762329219.1542985557
https://thingsmatic.com/2016/07/10/a-web-app-for-iot-data-visualization/
https://medium.com/@plotlygraphs/introducing-dash-5ecf7191b503
https://www.tutorialspoint.com/r/r_scatterplots.htm (R software)
http://www.math.nsysu.edu.tw/~lomn/homepage/R/R_plot.htm (R software)
https://alysivji.github.io/reactive-dashboards-with-dash.html (frameware,good)
(繼續閱讀...)
文章標籤

stanley 發表在 痞客邦 留言(0) 人氣(110)

  • 個人分類:資料科學
▲top
1

文章分類

  • 競賽心得 (1)
  • 機器學習 (3)
  • google Cloud platform (11)
  • 商業分析 (1)
  • 資料科學 (3)
  • Raspberry (9)
  • Linkit 7688 Duo (8)
  • Arduino (3)
  • Android程式開發 (17)
  • PHP & AJAX (2)
  • 木工生活 (8)
  • Project (1)
  • 英文學習 (1)
  • 科技與農業 (7)
  • ESP模組應用 (27)
  • EXCEL (1)
  • 電子分類 (15)
  • Python 程式設計 (52)
  • 未分類文章 (1)

熱門文章

  • (20,217)ESP8266電源與供電問題
  • (11,733)Python與Excel連結的openpyxl模組
  • (11,124)將民國年轉成西元年
  • (9,178)GPIO.BOARD與GPIO.BCM設定有何不同?
  • (8,587)Python Win32Com Excels基本操作
  • (7,394)ESP8266硬體線路連接
  • (4,727)免安裝的畫電路圖軟體
  • (3,001)免安裝版的Portable Python 2.7.6.1 下載
  • (1,290)Python & MicroPython 程式設計目錄
  • (1,036)使用Arduino 或電腦連結ESP8266-12(X) 初次應用

最新文章

  • LinkIt 7688 Duo package 套件管理工具-htop
  • LinkIt 7688 Duo 問題及解決方法
  • Wemos D1 Mini 腳位
  • LinkIt 7688 Duo 耗電電流
  • 臺南智慧農創松競賽心得
  • Dajngo 檔案結構
  • Python 各種官方說明文件
  • 資料分析常用程式收集
  • 安裝react 環境及Hello World
  • (8)SQLlite3 快速查詢

參觀人氣

  • 本日人氣:
  • 累積人氣:

個人資訊

stanley
暱稱:
stanley
分類:
數位生活
好友:
累積中
地區:

最新留言

  • [23/02/24] strongearth 於文章「馬達轉速及扭矩關係計算...」留言:
    省油15~25%、馬力和扭力增加20%、降引擎溫度20℃,自...
  • [22/04/09] 訪客 於文章「堆肥化過程重點掌握...」留言:
    原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間...
  • [22/04/08] vscyw.com 於文章「堆肥化過程重點掌握...」留言:
    非常好的po文,推薦給你們看看 https://vscyw...
  • [22/01/12] 康藥本鋪 kmed.tw 於文章「馬達轉速及扭矩關係計算...」留言:
    康藥本鋪商店 https://kmed.tw/index....
  • [21/12/04] 康藥本鋪 kmed.tw 於文章「LED解惑...」留言:
    增大丸 https://kmed.tw/ind...
  • [20/07/19] splashbaron 於文章「使用TP4056usb充電模組 DIY ...」留言:
    請問超過5.5V/1A輸入時,會被限制在5.5V/1A嗎?...
  • [20/02/26] Max 於文章「LinkIt 7688 Duo 電源管理...」留言:
    Urgent!!! 有關7688的技術問題想請教。 請大...
  • [19/10/27] stanley 於文章「ESP8266電源與供電問題...」留言:
    不好意思,這部份我没試過,所以無辦法給好什麼好的建議。...
  • [19/10/19] loveangelritah 於文章「ESP8266電源與供電問題...」留言:
    您好,我想要用12v的鹼性電池 透過齊納和電阻分壓給esp3...
  • [19/05/20] 黃偉華 於文章「LED解惑...」發表了一則私密留言

動態訂閱

文章精選

誰來我家

文章搜尋