我試圖編寫一個函數,寫入多個列表到一個單一的csv文件,我能夠獲得列標題寫入,但沒有任何數據。我的數據列表類似於[92,3801,2,22,4],第二個是[3.0,2,23,5],我正在尋找這方面的指導。謝謝!向csv寫入多個列表Python
import csv
def export_results(number_of_words_sentence,mean_word_per_sentence):
with open("assignment_7_results.csv", "w", newline="") as Assignment_7_results:
writer = csv.writer(Assignment_7_results)
writer.writerow(["Number of Words", "Words/Sentence"])
# Our .csv file will have two columns, one for the dict keys and one for the dict values
writer.writerows(number_of_words_sentence)
writer.writerows(mean_words_per_sentence)
顧名思義,''編寫者'寫_rows_,而不是列。您必須依次壓縮並逐個遍歷每對元素,並調用'authorow' –