# Part 2: 環境建置、資料蒐集 時長: 1 hr ## 環境建置- Anaconda ==將使用Jupyter Notebook Coding== Download Point: https://www.anaconda.com/download 下載過程參考: https://simplelearn.tw/anaconda-3-intro-and-installation-guide/ #### Jupyter Notebook [GitHub設定& GitHub Desktop的連結教學](https://www.youtube.com/watch?v=mcCPcjOdGfE) - 到GitHub的路徑裡建一個新檔(Python 3)  ## 主要資料型態: csv -> Dataframe - CSV (逗號分隔值) 檔案是特殊類型的檔案 - DataFrame是一種二維數據結構,可儲存不同類型的數據(包括字串、整數、浮點數等),由行列組成,類似表格型態,每一欄數據須為同一種資料型別,但不同欄可儲存不同資料型別。 - 運用Pandas套件處裡Dataframe資料 ``` # 讀取資料 df = pd.read_csv('persona.csv') #部分讀取 # (讀取頭幾筆資料、最後幾筆資料) df.head() df.tail() ``` [更多Pandas資訊](https://ithelp.ithome.com.tw/articles/10208425) ## 處裡Dataframe中的資料 ``` # 處理標籤欄位,確保每個關鍵字都被正確的分割為獨立的節點 df['標籤'] = df['標籤'].str.replace('、', ',').str.split(',') # 創建關鍵字與ID之間的映射對照表 keyword_to_ids = defaultdict(list) id_to_keywords = defaultdict(list) #轉換成對照表需要的樣態 for index, row in df.iterrows(): id = row['id'] id_to_keywords[id].append keywords = [keyword.strip() for keyword in row['標籤']] for keyword in keywords: keyword_to_ids[keyword].append(id) ```
×
Sign in
Email
Password
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