大帥哥
    • 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
    # 大數據 --- # opendata資料抓取方法 ## ✎按檢視資料 ![](https://hackmd.io/_uploads/BJz_AHaxp.png) ## ✎複製網址 ![](https://hackmd.io/_uploads/ryFdCSpgp.png) ## ✎wget '網址' -O 命名 (抓資料) ![](https://hackmd.io/_uploads/B1-CCraep.png) --- # 資料備份 --- ## ✎mkdir -p 建資料夾 opendata下面的Kids資料夾 ![](https://hackmd.io/_uploads/S1XKx8TlT.png) ## ✎tree的使用 ![](https://hackmd.io/_uploads/rJ2eWU6g6.png) ## ✎Cp複製 a 到 opendata/kids/ 下 ![](https://hackmd.io/_uploads/SJCDbIpxa.png) --- # 一般linux指令 --- ## ✎ls ![](https://hackmd.io/_uploads/S1kukLpgT.png) ## ✎ls -alh 收尋當前目錄資料大小 ![](https://hackmd.io/_uploads/HkkiTHpg6.png) ## ✎cat 檔案 | head(tail)-n 5 看(後面)前面5筆紀錄(可能會包含到標題) ![](https://hackmd.io/_uploads/Sk-V0Ual6.png) ## ✎cat前後一起輸出 ![](https://hackmd.io/_uploads/S10ZfPpla.png) ## ✎cat抓取 11 ~ 15的資料 cat head -n 15 |tail -n 5 ![](https://hackmd.io/_uploads/SJMNEP6l6.png) ## ✎当你运行这个命令时,它会跳过CSV文件的第一行,并显示CSV文件中的数据行数。这个命令将告诉你CSV文件中有多少行数据。 ![](https://hackmd.io/_uploads/rk4aSK8-6.png) ## ✎ | wc -l 收尋出來的個數 ## ✎ grep -E 收尋多個 ![](https://hackmd.io/_uploads/ryrEUFIWT.png) ![](https://hackmd.io/_uploads/rJfqY9LZa.png) ## ✎ 切欄位 | cut -d'切割符' -f2,5(要記得把標頭刪掉tail -n +2 ) 切開顯示2跟5的資料 ![](https://hackmd.io/_uploads/r1NCdK8-T.png) ## ✎ | sort (排續) | uniq(去重複) ![](https://hackmd.io/_uploads/BkhXKKIWa.png) ## sort -t',' (-r) -k5 -r是多到少排序 ,k5是以5為key排序 ![](https://hackmd.io/_uploads/BJ01lRyG6.png) ## ✎ | tr -d(刪除) '刪除ㄨ',-s(取代) '被取代物' '取代物' ![](https://hackmd.io/_uploads/rkiPm58bT.png) ![](https://hackmd.io/_uploads/H1AtX5IZp.png) ## ✎ tr去除雙引號 ![](https://hackmd.io/_uploads/SJuZvqLb6.png) ## ✎> 檔案名 (把修改過的資料轉存出來 ![](https://hackmd.io/_uploads/Hya9DqI-6.png) ## ✎unzip xx.zip(建議創一個資料夾丟進去分解) ![](https://hackmd.io/_uploads/BkoK4q8bp.png) ## ✎看檔案格式 file -bi 檔案 ![](https://hackmd.io/_uploads/ry13tlYM6.png) ## ✎轉檔案格式 iconv --from-code=BIG5 --to-code=UTF-8(看到ISO就用BIG5 ,UTF16就直接UTF16就好) ![](https://hackmd.io/_uploads/BkQw5lYz6.png) ## ✎awk -F ',' '{if ($5 == 0) print($2,$5)}' 以,切分,條件判斷當第五格=0時印出2跟第欄(如果後面接grep就代表,是去第二欄跟第五欄找有沒有你要找的字詞) ![](https://hackmd.io/_uploads/r1aueWtMa.png) --- # Hadoop指令 ## ✎hdfs dfs -ls + 目錄 (-R)(看hadoops叢集下的跟目錄) ![](https://hackmd.io/_uploads/HkZUDIagp.png) ## ✎hdfs dfs -get 檔案放置的目錄位置 放置位置(下載功能) ![](https://hackmd.io/_uploads/rkuHKUae6.png) ## ✎hdfs dfs -mkdir (-p ) 檔名(/{子目錄,子目錄,...}) hadoop建立資料夾(順便建子目路) ![](https://hackmd.io/_uploads/S1VDphkz6.png) ![](https://hackmd.io/_uploads/BJPWxTJza.png) ## ✎hdfs dfs -put 欲放檔案 hadoop目錄位置 放東西進去hadoop裡 ![](https://hackmd.io/_uploads/HJhuCh1MT.png) ## ✎hdfs dfs -rm (-r) 目錄 刪除目錄(-r是直接全刪不管裡面有沒有檔案) ![](https://hackmd.io/_uploads/H1kDyaJM6.png) --- --- # 練習 ## 抓取有幾個縣市 ### ✎cat 抓取這個資料的有幾個資料,第一步驟先使用cut去切第三欄位cut -c1-9代表3個字符 之後sort去排序uniq去重wc -l 得出數目 ![](https://hackmd.io/_uploads/Bkn246kG6.png) ![](https://hackmd.io/_uploads/SJ9EN6kMT.png) --- # Hive命令 ## hive 進入hive對話模式 ![](https://hackmd.io/_uploads/H1NytWFzT.png) ## dfs -ls; 可以查看目錄 ![](https://hackmd.io/_uploads/HyWWK-Ff6.png) ## quit; 退出對話模式 ![](https://hackmd.io/_uploads/B1kPt-tfT.png) ## 外部資料的定義表在linux的metastore_db裡 ![](https://hackmd.io/_uploads/ryRAsbFzT.png) ## nano 檔名 進入編輯模式 ![](https://hackmd.io/_uploads/H1bXWMtMa.png) ## 創表 ![](https://hackmd.io/_uploads/r1xfZfFfp.png) # 抓資料(抓到跟目錄,或者直接指定原目錄) ## 看有幾張表 ![image.png](https://hackmd.io/_uploads/ryoBdSfma.png)`` --- ``` ``` --- # 練習題ㄧ ### 最多幼兒園是那個縣市 ![MicrosoftTeams-image](https://hackmd.io/_uploads/rJE11CU46.jpg) 步驟一 取得資料集 wget 'https://stats.moe.gov.tw/files/school/106/k1_new.csv' -O opendata/k106.csv tail -n +2 opendata/k106.csv > k106.csv hdfs dfs -mkdir k8086/ hdfs dfs -put k106.csv.csv k8086/k8086.csv 步驟二 寫程式建資料表 cat k8086.hsql create external table k8086( code string, school string, pub string, city string, addr string, phone string ) row format delimited fields terminated by ',' stored as textfile location '/user/user95/k8086'; 執行程式 hive -f k8086.hsql 步驟三 hive -e 'select city,count(*) from k8086 group by city order by count(*) desc limit 5;' 2>/dev/null 執行結果 新北市最多 新北市 1134 --- # 練習題二 ### 那一年的替代役人數最多 ![MicrosoftTeams-image (1)](https://hackmd.io/_uploads/S11OkRIE6.jpg) hive 解法 : select year,SUM(trainees) from t20445 group by year order by SUM(trainees) desc; --- # 練習題三 ### 那間銀行的ATM 在台北市最多? ![9A7D3718-6A88-4353-BE4E-0A3018A290A7](https://hackmd.io/_uploads/By6O-RUNT.jpg) --- # 練習題四 ### 老師與學生總人數最多的是那間大學(不分學士、碩士、博士)? ### 練習題五 有最多博士系所的是那間大學? ![MicrosoftTeams-image (2)](https://hackmd.io/_uploads/ryEAJA8NT.jpg) 練習題四解題 : 步驟一 wget 'https://stats.moe.gov.tw/files/detail/106/106_sdata.csv' -O opendata/106std.csv head -n 5 opendata/106std.csv tail -n +2 opendata/106std.csv >106s.csv hdfs dfs -mkdir s106/ cat 106s.csv | cut -d',' -f10,2,4,5,6,7,8 > s106.csv hdfs dfs -put s106.csv s106/ 步驟二 nano s106.hsql create external table s9621( school string, faculty string, courses string, level string, student int, teacher int, city string ) row format delimited fields terminated by ',' stored as textfile location '/user/user95/s106'; 執行程式 hive -f s106.hsql 步驟三 $ hive -e 'select (school,faculty),SUM(student)+SUM(teacher) as num from s9621 group by (school,f aculty) order by num desc limit 5;' 2>/dev/null 執行結果如下:長庚科技大學,護理系,4654 {"col1":"長庚科技大學","col2":"護理系"}4654 {"col1":"新生醫護管理專科學校","col2":"護理科"}3778 {"col1":"耕莘健康管理專科學校","col2":"護理科"}3438 {"col1":"弘光科技大學","col2":"護理系"}2625 {"col1":"仁德醫護管理專科學校","col2":"護理科"}2580 --- # 練習題六 事故最多是哪一種車型? ### 練習七、發生事故最多是哪一天?(那年、那月、那日?) ### 承上題,練習八造成死亡數最多的是那種車型? ### 承上題,練習九平均造成死亡數最高的是那種車型? ![80D9D46B-81DA-410A-ADA6-92EE5C6AD42C](https://hackmd.io/_uploads/ry6EMAI4p.jpg) --- # 練習題十造成受傷數最高的是那種車型? ### 承上題,平均造成受傷數最高的是那種車型? ![6C01C61B-9037-4E38-8CDC-9DC046E7E4B5](https://hackmd.io/_uploads/BJnOM0IET.jpg) ``` ``` --- # 2023金象盃練習題 解題 #### https://hackmd.io/@ARf0rnelTWC01YddQj6dUA/S1YZU2T7T --- ``` ``` --- # Big Data 金象盃競賽競賽內容暨範例操作 ### http://bigdata2016.twisc.ncku.edu.tw/content.html --- ``` ``` --- # 2023 數據達人 (老師雲端的教材) ### https://drive.google.com/drive/folders/1r57WOor4M_7Y8PSvepASOsKAvkxyFTTP --- ``` ``` --- # Exel檔案處理 ## 第一題 ![image](https://hackmd.io/_uploads/HJdCm3rVT.png) ### 選取 範圍 => 插入選項(樞紐分析表) ![image](https://hackmd.io/_uploads/HJSpb3BN6.png) ### 排序 ![image](https://hackmd.io/_uploads/BJYj73HET.png) ### 遞減排序後 ![image](https://hackmd.io/_uploads/Hy-RHhHN6.png) ``` ``` --- ## 第二題 ![image](https://hackmd.io/_uploads/rJS11THNa.png) ### 選取 資料 => 篩選 ### 資料 => 移除重複選項 ### 選取 範圍 => 插入選項(樞紐分析表) ### 遞減排序後 ``` ``` --- ## 第五題 ![image](https://hackmd.io/_uploads/r1GAV48Na.png) ### 選取 資料 => 篩選 ### 選取 範圍 => 插入選項(樞紐分析表) 選取有80、443 port複製 ### 在進階篩選 ![image](https://hackmd.io/_uploads/ryho8NIV6.png) ### 選取全部 在選取 資料 =>排序 (選出熱門主機) ### 算出不安全比例後,排序(欄位選擇比例 從最大到最小) ### 把小數換成百分比例(選取資料 到常用的通用格式 選其他數字格式 百分比 小數第二位) ## 用python 將parquet轉csv檔 ![image](https://hackmd.io/_uploads/By9ki48Np.png) --- ![image](https://hackmd.io/_uploads/HyFzoEIN6.png) --- ![image](https://hackmd.io/_uploads/r1YSo48Na.png) ### 轉成 CSV檔後,是亂碼: #### 資料=>從文字檔 找原本的檔案 ``` ``` # 第二階段 虛擬機 ## 查詢電腦資訊 ![image](https://hackmd.io/_uploads/SJorgeC4p.png) ## dir 查詢目錄 ![image](https://hackmd.io/_uploads/ryCwlg0Ep.png) ## cd 查看目前的位置 ![image](https://hackmd.io/_uploads/SkRdexAV6.png) ## md:建資料夾 rd:刪除資料夾 ![image](https://hackmd.io/_uploads/Sk3Yxl0Ep.png) # ![image](https://hackmd.io/_uploads/BknaZgR4p.png) # ![image](https://hackmd.io/_uploads/Sk34flC4a.png) # ![image](https://hackmd.io/_uploads/Bk0pfx04a.png) ## 拷貝檔案 ![image](https://hackmd.io/_uploads/BkQVXgRVT.png) ## 刪除檔案 ![image](https://hackmd.io/_uploads/SJJUXgAEp.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