task.py


Figure 2:\colon 使用csv file傳遞校正答案

import pandas as pd
import os

cwd = os.getcwd() + os.sep
root_dir = cwd.replace(os.sep + 'codes' + os.sep,'')
answer_M_folder = 'Answer_M'
if not os.path.isdir(os.path.join(root_dir, answer_M_folder)):
    os.makedirs(os.path.join(root_dir, answer_M_folder))


### You must Modified ###
out_csv_filename = 'task1.csv'
ID=[379, 442, 702, 713, 717, 915, 1106, 1193, 1254, 1520]
answer = [1, 3, 4, 1, 2, 2, 3, 1, 4, 1]
### You must Modified ###

answer_dict = {"ID": ID, "answer": answer}
df = pd.DataFrame(answer_dict)
print(df)
dst = os.path.join(root_dir, answer_M_folder, out_csv_filename)
df.to_csv(dst)

Realization

  1. 用spyder開啟task.py
  2. 執行task.py
  3. running setting for task.py
  4. 在ipython console顯示執行結果
  5. 執行完task.pykaggle2_answer_M會新增answer_M資料夾以及csv檔

results matching ""

    No results matching ""