# 程式設計(第24組) 25/04/2022 組長:黃凱葶 110251039 管院學士班學士班1年級 組員:林世鎧 110211052 經濟系學士班1年級 組員:周芃君 110211008 經濟系學士班1年級 組員:蘇家陞 110211033 經濟系學士班1年級 --- ### [期中考 Q&A](https://colab.research.google.com/drive/14JVxLYE6ndI8nKb84sCY9xa7ohYoM7MN#scrollTo=2McwkRR3iRlX) 考題解答、重點: 1. **閱讀題** 1. ⇒`1 2 3` (覆寫變數) 2. ⇒`22` (文本組合) 3. ⇒`12` (運算子) 4. ⇒`1 1 2 2 3 3 4 4 5 5 5` (for迴圈) 5. ⇒`{"Berserker's Greaves", "Doran's Blade", "Caulfield's Warhammer"}` (Set集合) 6. ⇒`55` (for迴圈、range函數) 7. ⇒`['A', 'B', 'C', 'D', 'E'] ['C', 'D']` (列表/切片) 8. ⇒`讀取/content/drive/My Drive路徑底下名為的aprilNetIncome的csv檔,印出之中的material_expense欄位` (Pandas模組、掛勾元件) 2. **應用題** 1. | 次數 | No.0 | No.1 | No.2 | No.3 | | ---- | ---- | ---- | ---- | ---- | | 0次 | 9 | 18 | 13 | 6 | | 1次 | 9 | 13 | 18 | 6 | | 2次 | 9 | 13 | 6 | 18 | | 3次 | 9 | 6 | 13 | 18 | | 4次 | 6 | 9 | 13 | 18 | | 終 | 6 | 9 | 13 | 18 | 2. ``` list = [1,2,3,4,5,6,7,8,9] for i in list: for j in list: print(i,"x",j,"=",i*j) #鑲嵌迴圈,內迴圈將在外迴圈的每次走訪中執行一次 ``` 3. ``` list = [1,3,7,13,15,16,22,29] count = 0 for i in range(len(list)): if ( 15 > list[i] ): count = count + 1 print(count) #運算子 ``` 4. (列表) ``` list = ['蘋果', '香蕉', '葡萄'] for i in range(len(list)): print(list[i]) if (i == len(list)-1): print(list[0] + list[len(list)-1]) else : print(list[i] + list[i+1]) ``` 5. (Pandas模組、df表格) ``` import pandas as pd grades = { "姓名": ["小明", "小美", "小花", "小華","小文"], "國文": [71,80,58,59,44], "數學": [92,15,66,70,68], "英文": [68,99,63,72,87] } df = pd.DataFrame(grades) #(1) print(df) print("----") #(2) print(df.loc[[0,2],["姓名","國文","數學"]]) print("----") #(3) df.at[3,"英文"] = 77 print(df.loc[[3],["姓名","英文"]]) print("----") #(4) print(df[df["國文"] < 60]) ``` 6. (字典) ``` #先建立一個字典 breakfast = {"香煎培根堡":35,"鮮蔬起士堡":40,"花生培根山明治":60,"花生燻雞山明治":65,"洋芋蛋沙拉手捲餅":45,"香草豬排手捲餅":55} #(1) print("-----") print(breakfast) #(2) print("-----") print(breakfast.get("花生培根山明治")) #(3) print("-----") for i in breakfast: print(i) #(4) print("-----") for i in breakfast: breakfast[i] += 5 print(breakfast) ``` 7. (字典) ``` #先建立一個字典 employee = {"001":"王重陽", "002":"張三丰", "003":"謝遜", "004":"謝安", "005":"李世民", "006":"謝靈運" } #(1)印出所有內容 print("-----") print(employee) #(2)找出所有姓"謝"的員工名字與編號 print("-----") for a,b in employee.items(): if "謝" in b: print(a,b) #(3)找出所有員工的姓氏,不重複 print("-----") nameList = set() for i in employee.values(): nameList.add(i[0]) print(nameList) #(4)印出所有員工的入職歡迎詞 print("-----") for i,j in employee.items(): print(f"歡迎{i}號員工{j}入職") ``` --- ### 期末專題 #### 格式與內容要求 * **研究專題要求:** >研究專題 >研究背景 >研究問題 >資料來源 >資料欄位的意義 >資料清理 >資料視覺化 >指標/統計量 >發現與結論 >參考文獻 * **技術基本要求:** >使用Colab展示 >要有資料檔案,檔案需為excel或csv格式。 >資料檔案要放到google drive內。 >用pandas讀取檔案 >用dataframe呈現整體資料 >資料檢查與資料清理 >把資料視覺化 >根據資料,算出一些統計量或者有意義的指標 *※ TA請建立一個colab連結的上傳表單,讓小組上傳自己的程式碼,以及小組專題的說明影片。* --- ### [小組期末報告](https://colab.research.google.com/drive/1ZY8k0L0_K_7JH6UPy0ntfMRT6H2bwlnW)