TQC+ 網頁資料擷取與分析_Python_103_勞保投保薪資分級表

文、意如

1. 題目說明:

請開啟PYD01.py檔案,依下列題意進行作答,使輸出值符合題意要求。作答完成請另存新檔為PYA01.py再進行評分。

程式所產出的檔案,須輸出與程式同一層資料夾。

2. 設計說明:

請撰寫一程式,讀取勞保投保薪資分級表read.json內的資料後,將資料轉存為write.yaml。

3. 輸入輸出:

輸入說明

讀取read.json

輸出說明

將資料輸出至write.yaml

範例輸入

範例輸出

 

read.json
[{"身分別":"一般勞工","投保薪資等級":"第1級","月薪資總額":"22000元以下","月投保薪資":"22000元"},{"身分別":"一般勞工","投保薪資等級":"第2級","月薪資總額":"22001元至22800元","月投保薪資":"22800元"},{"身分別":"一般勞工","投保薪資等級":"第3級","月薪資總額":"22801元至24000元","月投保薪資":"24000元"},{"身分別":"一般勞工","投保薪資等級":"第4級","月薪資總額":"24001元至25200元","月投保薪資":"25200元"},{"身分別":"一般勞工","投保薪資等級":"第5級","月薪資總額":"25201元至26400元","月投保薪資":"26400元"},{"身分別":"一般勞工","投保薪資等級":"第6級","月薪資總額":"26401元至27600元","月投保薪資":"27600元"},{"身分別":"一般勞工","投保薪資等級":"第7級","月薪資總額":"27601元至28800元","月投保薪資":"28800元"},{"身分別":"一般勞工","投保薪資等級":"第8級","月薪資總額":"28801元至30300元","月投保薪資":"30300元"},{"身分別":"一般勞工","投保薪資等級":"第9級","月薪資總額":"30301元至31800元","月投保薪資":"31800元"},{"身分別":"一般勞工","投保薪資等級":"第10級","月薪資總額":"31801元至33300元","月投保薪資":"33300元"},{"身分別":"一般勞工","投保薪資等級":"第11級","月薪資總額":"33301元至34800元","月投保薪資":"34800元"},{"身分別":"一般勞工","投保薪資等級":"第12級","月薪資總額":"34801元至36300元","月投保薪資":"36300元"},{"身分別":"一般勞工","投保薪資等級":"第13級","月薪資總額":"36301元至38200元","月投保薪資":"38200元"},{"身分別":"一般勞工","投保薪資等級":"第14級","月薪資總額":"38201元至40100元","月投保薪資":"40100元"},{"身分別":"一般勞工","投保薪資等級":"第15級","月薪資總額":"40101元至42000元","月投保薪資":"42000元"},{"身分別":"一般勞工","投保薪資等級":"第16級","月薪資總額":"42001元至43900元","月投保薪資":"43900元"},{"身分別":"一般勞工","投保薪資等級":"第17級","月薪資總額":"43901元以上","月投保薪資":"45800元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第1級","月薪資總額":"6000元以下","月投保薪資":"6000元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第2級","月薪資總額":"6001元至7500元","月投保薪資":"7500元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第3級","月薪資總額":"7501元至8700元","月投保薪資":"8700元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第4級","月薪資總額":"8701元至9900元","月投保薪資":"9900元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第5級","月薪資總額":"9901元至11100元","月投保薪資":"11100元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第6級","月薪資總額":"11101元至12540元","月投保薪資":"12540元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第7級","月薪資總額":"12541元至13500元","月投保薪資":"13500元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第8級","月薪資總額":"13501元至15840元","月投保薪資":"15840元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第9級","月薪資總額":"15841元至16500元","月投保薪資":"16500元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第10級","月薪資總額":"16501元至17280元","月投保薪資":"17280元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第11級","月薪資總額":"17281元至17880元","月投保薪資":"17880元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第12級","月薪資總額":"17881元至19047元","月投保薪資":"19047元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第13級","月薪資總額":"19048元至20008元","月投保薪資":"20008元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第14級","月薪資總額":"20009元至21009元","月投保薪資":"21009元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第15級","月薪資總額":"21010元至22000元","月投保薪資":"22000元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第16級","月薪資總額":"22001元至22800元","月投保薪資":"22800元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第17級","月薪資總額":"22801元至24000元","月投保薪資":"24000元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第18級","月薪資總額":"24001元至25200元","月投保薪資":"25200元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第19級","月薪資總額":"25201元至26400元","月投保薪資":"26400元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第20級","月薪資總額":"26401元至27600元","月投保薪資":"27600元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第21級","月薪資總額":"27601元至28800元","月投保薪資":"28800元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第22級","月薪資總額":"28801元至30300元","月投保薪資":"30300元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第23級","月薪資總額":"30301元至31800元","月投保薪資":"31800元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第24級","月薪資總額":"31801元至33300元","月投保薪資":"33300元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第25級","月薪資總額":"33301元至34800元","月投保薪資":"34800元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第26級","月薪資總額":"34801元至36300元","月投保薪資":"36300元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第27級","月薪資總額":"36301元至38200元","月投保薪資":"38200元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第28級","月薪資總額":"38201元至40100元","月投保薪資":"40100元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第29級","月薪資總額":"40101元至42000元","月投保薪資":"42000元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第30級","月薪資總額":"42001元至43900元","月投保薪資":"43900元"},{"身分別":"庇護性身心障礙者","投保薪資等級":"第31級","月薪資總額":"43901元以上","月投保薪資":"45800元"},{"身分別":"部分工時勞工","投保薪資等級":"第1級","月薪資總額":"11100元以下","月投保薪資":"11100元"},{"身分別":"部分工時勞工","投保薪資等級":"第2級","月薪資總額":"11101元至12540元","月投保薪資":"12540元"},{"身分別":"部分工時勞工","投保薪資等級":"第3級","月薪資總額":"12541元至13500元","月投保薪資":"13500元"},{"身分別":"部分工時勞工","投保薪資等級":"第4級","月薪資總額":"13501元至15840元","月投保薪資":"15840元"},{"身分別":"部分工時勞工","投保薪資等級":"第5級","月薪資總額":"15841元至16500元","月投保薪資":"16500元"},{"身分別":"部分工時勞工","投保薪資等級":"第6級","月薪資總額":"16501元至17280元","月投保薪資":"17280元"},{"身分別":"部分工時勞工","投保薪資等級":"第7級","月薪資總額":"17281元至17880元","月投保薪資":"17880元"},{"身分別":"部分工時勞工","投保薪資等級":"第8級","月薪資總額":"17881元至19047元","月投保薪資":"19047元"},{"身分別":"部分工時勞工","投保薪資等級":"第9級","月薪資總額":"19048元至20008元","月投保薪資":"20008元"},{"身分別":"部分工時勞工","投保薪資等級":"第10級","月薪資總額":"20009元至21009元","月投保薪資":"21009元"},{"身分別":"部分工時勞工","投保薪資等級":"第11級","月薪資總額":"21010元至22000元","月投保薪資":"22000元"},{"身分別":"部分工時勞工","投保薪資等級":"第12級","月薪資總額":"22001元至22800元","月投保薪資":"22800元"},{"身分別":"部分工時勞工","投保薪資等級":"第13級","月薪資總額":"22801元至24000元","月投保薪資":"24000元"},{"身分別":"部分工時勞工","投保薪資等級":"第14級","月薪資總額":"24001元至25200元","月投保薪資":"25200元"},{"身分別":"部分工時勞工","投保薪資等級":"第15級","月薪資總額":"25201元至26400元","月投保薪資":"26400元"},{"身分別":"部分工時勞工","投保薪資等級":"第16級","月薪資總額":"26401元至27600元","月投保薪資":"27600元"},{"身分別":"部分工時勞工","投保薪資等級":"第17級","月薪資總額":"27601元至28800元","月投保薪資":"28800元"},{"身分別":"部分工時勞工","投保薪資等級":"第18級","月薪資總額":"28801元至30300元","月投保薪資":"30300元"},{"身分別":"部分工時勞工","投保薪資等級":"第19級","月薪資總額":"30301元至31800元","月投保薪資":"31800元"},{"身分別":"部分工時勞工","投保薪資等級":"第20級","月薪資總額":"31801元至33300元","月投保薪資":"33300元"},{"身分別":"部分工時勞工","投保薪資等級":"第21級","月薪資總額":"33301元至34800元","月投保薪資":"34800元"},{"身分別":"部分工時勞工","投保薪資等級":"第22級","月薪資總額":"34801元至36300元","月投保薪資":"36300元"},{"身分別":"部分工時勞工","投保薪資等級":"第23級","月薪資總額":"36301元至38200元","月投保薪資":"38200元"},{"身分別":"部分工時勞工","投保薪資等級":"第24級","月薪資總額":"38201元至40100元","月投保薪資":"40100元"},{"身分別":"部分工時勞工","投保薪資等級":"第25級","月薪資總額":"40101元至42000元","月投保薪資":"42000元"},{"身分別":"部分工時勞工","投保薪資等級":"第26級","月薪資總額":"42001元至43900元","月投保薪資":"43900元"},{"身分別":"部分工時勞工","投保薪資等級":"第27級","月薪資總額":"43901元以上","月投保薪資":"45800元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第1級","月薪資總額":"13500元以下","月投保薪資":"13500元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第2級","月薪資總額":"13501元至15840元","月投保薪資":"15840元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第3級","月薪資總額":"15841元至16500元","月投保薪資":"16500元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第4級","月薪資總額":"16501元至17280元","月投保薪資":"17280元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第5級","月薪資總額":"17281元至17880元","月投保薪資":"17880元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第6級","月薪資總額":"17881元至19047元","月投保薪資":"19047元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第7級","月薪資總額":"19048元至20008元","月投保薪資":"20008元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第8級","月薪資總額":"20009元至21009元","月投保薪資":"21009元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第9級","月薪資總額":"21010元至22000元","月投保薪資":"22000元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第10級","月薪資總額":"22001元至22800元","月投保薪資":"22800元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第11級","月薪資總額":"22801元至24000元","月投保薪資":"24000元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第12級","月薪資總額":"24001元至25200元","月投保薪資":"25200元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第13級","月薪資總額":"25201元至26400元","月投保薪資":"26400元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第14級","月薪資總額":"26401元至27600元","月投保薪資":"27600元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第15級","月薪資總額":"27601元至28800元","月投保薪資":"28800元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第16級","月薪資總額":"28801元至30300元","月投保薪資":"30300元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第17級","月薪資總額":"30301元至31800元","月投保薪資":"31800元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第18級","月薪資總額":"31801元至33300元","月投保薪資":"33300元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第19級","月薪資總額":"33301元至34800元","月投保薪資":"34800元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第20級","月薪資總額":"34801元至36300元","月投保薪資":"36300元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第21級","月薪資總額":"36301元至38200元","月投保薪資":"38200元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第22級","月薪資總額":"38201元至40100元","月投保薪資":"40100元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第23級","月薪資總額":"40101元至42000元","月投保薪資":"42000元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第24級","月薪資總額":"42001元至43900元","月投保薪資":"43900元"},{"身分別":"職訓機構受訓者","投保薪資等級":"第25級","月薪資總額":"43901元以上","月投保薪資":"45800元"}]
PYD01.py
# 載入 yaml 與 json 模組
import ___
import ___

# 讀取 json 檔案
with ___("___", encoding='utf-8-sig') as file:
    data = ___.___(___)

# 寫入 yaml 檔案
with ___("___", "___", encoding="utf-8") as f:
    ___.___(data, f, default_flow_style=False, allow_unicode=True)
        


參考解答

# 載入 yaml 與 json 模組
import yaml
import json

# 讀取 json 檔案
with open("read.json", encoding='utf-8') as file:
    data = json.load(file)  # 使用 json.load() 函數將 JSON 檔案解析為 Python 資料結構

# 寫入 yaml 檔案
with open("./write.yaml", "w", encoding="utf-8") as f:
    yaml.dump(data, f, default_flow_style=False, allow_unicode=True)
    # 使用 yaml.dump() 函數將 Python 資料結構轉換為 YAML 格式並寫入檔案
    # - default_flow_style=False: 確保 YAML 輸出是人類可讀的,而不是一行內容
    # - allow_unicode=True: 允許在 YAML 中使用 Unicode 字元,以處理非英語文字

執行時如果出現找不到yaml

輸入指令安裝:pip install pyyaml

執行後會產生write.yaml檔

 

 

參考

 

Yiru@Studio - 關於我 - 意如