Save Answers to CSV file

(in main.py)

83  answers = {'ID':ID, 'Answer':answer_per_Q}
84  print(answers)
85  df = pd.DataFrame(data=answers, dtype=np.int32)
86  print(df)
87  df.to_csv('out.csv',index=False)

首先由IDanswer_per_Q建立一個字典(dictionary)資料answersID是問題的編號,answer_per_Q是問題的答案。接下來呼叫pd.Dataframeanswers轉換成dataframe的格式,物件名稱叫df,最後呼叫df的helper function to_csv把結果存成out.csvindex=False是告訴pandas不要把pandas自己編碼(index)秀出來。

results matching ""

    No results matching ""