蔡至洹
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    第一周 == 1. 指令 輸出 print() #要輸出非變數與參數時須加上上引號 ex: ```python= print("程式設計") # 執行結果:程式設計 x=2 print(x) # 執行結果:2 ``` :::danger - 程式碼的部分可以善用共筆標籤框起來,如上(請看編輯模式) - python 中的註解方式:在註解前方加上一個 # > [name=By 助教] ::: 輸入 input() 2. Python Arithmetic Operators +(加) ex: x=5 y=6 print(x+y) 11 -(減) ex: x=6 y=5 print(x-y) 1 *(乘) ex: x=6 y=5 print(x*y) 30 /(除) ex: x=6 y=3 print(x/y) 2 %(模除) ex: x=5 y=2 print(x%y) #5/2=2.....1 5%2=1 1 **(次方) ex: x=2 print(x**3) #2*2*2=8 8 // (取商數) ex: x=5 y=2 print(x//y) #5/2=2.....1 5//2=2 2 3. Python Assignment Operators =(指定) ex: x=5 #將5指定給x += ex: x = 5 x += 3 #same as x=x+3 print(x) 8 以此類推任何的Arithmetic Operators加上=(任意數字)後皆變成x=x Arithmetic Operators(任意數字) 4. Python Comparison Operators ==(相等) #須注意=跟==不一樣,x=y是將y指定給x,而x==y是x與y相等 ex: x=3 y=3 x==y ture !=(等式不相等) ex: x=3 y=2 x!=y ture <(小於) >(大於) <=(小於等於) >=(大於等於) 5. Python Logical Operators and 符號&(兩者皆須符合) ex: x=5 x<6 and x>3 ture or 符號|(兩者只須符合一個即可) ex: x=5 x<6 or x>6 ture not 符號~(否定) ex: x=5 print(not(x > 3 and x < 10)) false 6. 程式執行順序 ex: x=5 y=6 print(x+y) 11 這段程式碼中電腦是先將5指定給x,再將6指定給y,之後先計算print括號內的x+y最後再將x+y輸出。 第二周:小組作業題目解題 === 1.import math x=math.sqrt(2) y=math.sqrt(7) print(x*y) Ans:3.7416573867739418 2.import math pow(121,2)+2*121*79+pow(79,2) And:40000 3.import math pow(10,6)*pow(10,6)/pow(10,4) Ans:100000000 4.168*317 And:53256 5.import math 6/(math.sqrt(12-2*math.sqrt(27))) And:4.732050807568878 6.import math math.sqrt((3+math.sqrt(5))/2) Ans:1.618033988749895 7.import math (math.sqrt(4038)+math.sqrt(4036))*(math.sqrt(2019)-math.sqrt(2018)) Ans:1.41421356237317 8. 9. 10.import math abs(2-8)+abs(4.5-7)-abs(5/4-4/5) Ans:8.05 11.import math pow(246,5)/pow(123,5)+pow(1107,4)/pow(369,4)+pow(936,3)/pow(234,3) And:177 12.import math math.sqrt(1/pow(5,2)+1/pow(4,2)+1) Ans:1.05 筆記: Python 基本語法 Indentation(縮排) ![](https://i.imgur.com/2LA96iV.png) (1)使用時,必須要有空格,沒有空格,會被給錯誤 Ex: ![](https://i.imgur.com/uHQTi1t.png) (2)需使用相同數量的空格,否則會被給錯誤 Ex:![](https://i.imgur.com/O7kLOJ9.png) 第四周小組筆記 === Python 基本語法 Indentation(縮排) ![](https://i.imgur.com/2LA96iV.png) (1)使用時,必須要有空格,沒有空格,會被給錯誤 Ex: ![](https://i.imgur.com/uHQTi1t.png) (2)需使用相同數量的空格,否則會被給錯誤 Ex:![](https://i.imgur.com/O7kLOJ9.png) 3/14 === #串列可能使用的工具 ![](https://i.imgur.com/jJ5ogvh.jpg) 範例: 1. ![](https://i.imgur.com/ZNErVvb.jpg) 2. ![](https://i.imgur.com/8Z6JOhH.jpg) #彙總函數 print(len(行列))#長度 print(max(行列))#最大值 print(min(行列))#最小值 print(sum(行列))#加總 3.迴圈的概念及範例 指在串列中每個元素都走訪一遍,再來印出符合條件的元素 範例: 範例1.![](https://i.imgur.com/bpL8p4o.jpg) 範例2.![](https://i.imgur.com/eeZ9p4Z.jpg) 3/21 === 迴圈的利用 紙筆小考解題 **第一題** ![](https://i.imgur.com/e1c3Z7N.jpg) 解題: ![](https://i.imgur.com/MrsbiNL.jpg) **第二題** ![](https://i.imgur.com/PuamSH7.jpg) 解題: ![](https://i.imgur.com/KRm97s1.jpg) **第三題** ![](https://i.imgur.com/kPAi3Dp.jpg) 解題: ![](https://i.imgur.com/awrVW66.jpg) **第四題**! [](https://i.imgur.com/31vPSEn.jpg) 解題: ![](https://i.imgur.com/yB3HzIk.jpg) **第五題** ![](https://i.imgur.com/NJjLjre.jpg) 解題: ![](https://i.imgur.com/SX50xbN.jpg) **第六題** ![](https://i.imgur.com/r5JjtIj.jpg) 解題: ![](https://i.imgur.com/vyFJys3.jpg) 3/28 == ## 字典 Dictionaries 透過鍵(key)來查找值(value) 範例: ![](https://i.imgur.com/AF17MX4.png) ![](https://i.imgur.com/ruuqhOa.png) ![](https://i.imgur.com/hjZpdEi.png) ### Key() 的使用 可列出所有鍵 範例: ![](https://i.imgur.com/gmKI0DH.png) ### Values 的使用 可得字典中的值 範例: ![](https://i.imgur.com/eABNwus.png) ### 增加項目 car = { "brand": "Porsche", "model": "911", "year": 1963 } x = car.keys() car["age"]="20" print(x) ![](https://i.imgur.com/VHp216s.png) ### 更新字典中的值 方法1 : car = { "brand": "Porsche", "model": "911", "year": 1963 } x =car.values() print(x) car["year"] = 1964 print(x) #新增項目之後 ![](https://i.imgur.com/Mr6Hju8.png) 方法二:使用 update() car = { "brand": "Porsche", "model": "911", "year": 1963 } x =car.values() car.update({"year":"1964"}) print(x) ![](https://i.imgur.com/PcTf4IM.png) ### 使用for 迴圈 使用字典練習資料集(學號與姓名) dict = { "109213504”:“麥禮仁", "110211049”:“稅正祺", "110211003”:“林志宬", "110251009”:“王博賢" } 範例1: ![](https://i.imgur.com/GpxIk8a.png) 範例2: ### Set集合 ``` 集合用於在單個變數中存儲多個項,並且集合為無序的,因此無法確定專案將以哪種順序顯示。也不可重複 ``` 範例: ![](https://i.imgur.com/MSQDy5X.png) ``` 增加項目加入集合 ``` 方法一:add() 方法二:update() ``` 集合(sets)從 0,1,2,3...開始計算 ``` ![](https://i.imgur.com/PLiBJ7h.png) ``` 算len()有包含標點符號 ``` 4/11 == # 讀取與寫入雲端資料夾的檔案 (上課老師範例) ``` 必須先到Google Drive建立資料夾 檔名 : ___TestData ``` 寫入文字檔案 ``` # 手工掛載雲端硬碟 # 寫入CSV with open('/content/drive/MyDrive/___DataSet//001_Hello.txt', 'w') as f: f.write('Hello Google Drive 蔡至洹') # 讀取CSV with open('/content/drive/MyDrive/___DataSet//001_Hello.txt', 'r') as f: ss=f.read() print(ss) # 刪除檔案 import os if os.path.exists("/content/drive/MyDrive/___DataSet//001_Hello.txt"): os.remove("/content/drive/MyDrive/___DataSet//001_Hello.txt") print("檔案已經刪除") else: print("檔案不存在") ``` # excel 應用 ``` #讀取雲端硬碟中的excel檔 import pandas as pd df = pd.read_excel('/content/drive/My Drive/___DataSet/001_Income_F.xlsx') df ``` ``` #讀取雲端硬碟中的excel檔 import pandas as pd data = pd.read_excel("/content/drive/My Drive/___DataSet/110 學年度全國大專校院及校長名錄(含學校本部地址).xlsx") data ``` 讀取csv檔 ``` import pandas as pd df = pd.read_csv('/content/drive/My Drive/___DataSet/opendata110road.csv') df ``` # Pandas DataFrame ``` 主要用來處理雙維度的資料,也就是具有列(row)與欄(column)的表格式資料集,所以經常應用於讀取CSV檔案、網頁表格或資料庫等 ``` 使用字典建立df ``` import pandas as pd grades = { "學號": [ "A001", "A002", "A003", "A004", "A005"], "體重": [60, 50, 80, 75, 72], "身高": [165, 157, 182, 175, 170] } df = pd.DataFrame(grades) print(df) ``` ![](https://i.imgur.com/u8p9jBr.png) 利用陣列建立df ![](https://i.imgur.com/R6krWWT.png) 4/25 == # 個人專案 研究專題 1. 研究背景 2. 研究問題 3. 資料來源 4. 資料欄位的意義 5. 資料清理 6. 資料視覺化 7. 指標/統計量 8. 研究發現 9. 結論 10. 參考文獻 4.技術基本要求 * 使用Colab展示 * 要有資料檔案,檔案需為excel或csv格式。 * 資料檔案要放到google drive內。 * 用pandas讀取檔案 * 用dataframe呈現整體資料 * 資料檢查與資料清理 * 把資料視覺化 * 根據資料,算出一些統計量或者有意義的指標 5/2 == # 課後老師遺留問題:吉尼係數是什麼 ? 定義 : 是吉尼係數乘100倍作百分比表示。在民眾所得中,吉尼係數最大為「1」,最小為「0」。前者表示居民之間的年所得分配絕對不平均(即該年所有所得都集中在一個人手裏,其餘的國民沒有所得),而後者則表示居民之間的該年所得分配絕對平均,即人與人之間所得絕對平等,吉尼係數的實際數值只能介於這兩種極端情況,即0~1之間。 ![](https://i.imgur.com/JR1mxVN.png) # 使用Python計算吉尼係數 ![](https://i.imgur.com/IVjA5np.png) 得下圖 : ![](https://i.imgur.com/NseQcgA.png) # 期中課堂加分作業 [](https://)https://colab.research.google.com/drive/1TuCBChckJgCnX6OK65qWnFw8nflzPxrP#scrollTo=VtAiD4b35nhS 5/9 == 完成小組專題 : 總結的部分(已完成) 課堂練習 https://hypebeast.com/zh/2021/10/nba-highest-paid-players-2021-22-lebron-james 根據網站做出羅倫茲曲線以及吉尼係數 5/16 == # 函數 上課範例 https://www.w3schools.com/python/python_functions.asp) 課堂小考 1.請定義一個函數myFunction,傳入一個參數n。此函數可以計算出1,2,…,n的總和。函數能傳回後的總和。(必須用for迴圈完成)。 解 : ![](https://i.imgur.com/AlrK8sr.png) 2.請定義一個函數myFunction,傳入一個參數n。此函數可以找出1,2,…,n的之間2的倍數,並列印出到螢幕上。(必須用for迴圈完成) 解 : ![](https://i.imgur.com/pjKzDBu.png) 3.請在螢幕上印出如下圖案 (必須用for迴圈完成) ![](https://i.imgur.com/HpBdD5w.png) 解 : ![](https://i.imgur.com/3cqecNp.png) 5/23 == (1).請定義一個函數myFunction,傳入一個參數n。此函數可以計算出123…n的總和。函數能傳回後的總和。(必須用for迴圈完成) ![](https://i.imgur.com/mFgLNQo.png) (2).2.請定義一個函數myFunction。此函數可以列出1到9的乘法表,列出的方式如下所示:(必須用for迴圈完成) 乘法1 11=1 12=3 … 1*9=9 乘法2 21=2 22=4 … 2*9=18 乘法3 … 乘法9 91=9 92=18 … 9*9=81 ![](https://i.imgur.com/MtvwvBJ.png) (4).請定義一個函數myFunction,傳入一個參數n。此函數可以找出所有除數,這些除數除以n能夠整除,並將這些因數印出到螢幕上。例如:假設你傳入參數10,函數印出 1,2,5,10。列印時從1印出。(必須用for迴圈與判斷式完成) ![](https://i.imgur.com/W1B1yCt.png) (5).請定義一個函數myFunction,傳入一個參數n。此函數可以找出所有除數,這些除數除以n不能夠整除,並將這些因數印出到螢幕上。例如:假設你傳入參數10,函數印出 3,6,7,8,9。除數要小於n(必須用for迴圈與判斷式完成) ![](https://i.imgur.com/hMAzaZt.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully