---
# System prepended metadata

title: Python資料分析1 (黃俊毓老師)
tags: [資料分析, python]

---

# Python資料分析1 (黃俊毓老師)
## Multi-List (多維陣列)
#### Workshop
* 針對這些學生，第一次段考的分數依序如下:
```py=
[{"score": 51}, {"score": 64}, {"score": 63}, {"score": 66}, {"score": 62}, {"score": 63}, {"score": 70}, {"score": 60}, {"score": 64}, {"score": 52}, {"score": 66}, {"score": 64}, {"score": 55}, {"score": 60}, {"score": 52}, {"score": 69}]
```
  * 產生一個 2-dim 陣列，每個陣列的元素 (elem) 包含 1 個字典如下:
  {“name”:“stu-0”, “score”:60}   <-- socre 請參考上面的資料
  * 使用者需要撰寫一個迴圈來遍覽這個 2 維陣列，並手動輸入分數 (可以隨意打)
  * 最後，請印出這個 2-dim 陣列，元素 (elem) 需要包含
    * delta : 兩次成績之差
    * {“name”:“stu-0”, “score”:60, delta:-10}
  * 請注意! 印出來的 output 需要是 (4x4) 2 維陣列!
#### Code:
```py=
arr1 = [{"score": 51}, {"score": 64}, {"score": 63}, {"score": 66}, {"score": 62}, {"score": 63}, {"score": 70}, {"score": 60}, {"score": 64}, {"score": 52}, {"score": 66}, {"score": 64}, {"score": 55}, {"score": 60}, {"score": 52}, {"score": 69}]
counter = 0
arr2 = []
for i in range(4):
    row=[]
    for j in range(4):
        obj = {"name": f'stu-{counter}', "score": arr1[counter]["score"]}
        row.append(obj)   
        counter += 1
    arr2.append(row)
counter = 0
for i in range(4):
    for j in range(4):
        scoreCur = int(input(f'請輸入stu-{counter}的分數:'))
        diff = scoreCur - arr2[i][j]['score']
        arr2[i][j] = {"name": f'stu-{counter}', "score": arr1[counter]["score"], "delta": diff}
        counter +=1
print(arr2)
```
#### Output:
![](https://hackmd.io/_uploads/rywjC-KNh.png)
---
## Series
[補充](https://www.learncodewithmike.com/2020/10/python-pandas-series-tutorial.html)
#### Workshop
![](https://hackmd.io/_uploads/rkr75mF43.png)

```py=
arr1 = input("請輸入 10 個英文或數字，以 , 隔開 :").replace(" ","").split(",")
arr_int = []
arr_cha = []

for i in arr1:
    if i.isdigit():
        arr_int.append(int(i))
    else:
        arr_cha.append(i)

ans = input("請輸入你要查詢的型態: ")
if ans in 'int':
    for i in arr_int:
        print(f'int {i}')
elif ans in 'str':
    for i in arr_cha:
        print(f'str {i}')
```
* Workshop
某學生段考成績如下
{“english”: 80, “chinese”: 60, “math”: 70}
以 Series 求文科總分？
```py=
import pandas as pd

a = {"english": 80, "chinese": 60, "math": 70}
b = pd.Series(a)
print(b[0]+b[1])
```

###### tags: `python` `資料分析`

