簡體   English   中英

如何以這種方式顯示 CSV 中的 200 行數據 '' line[0].split(';') "

[英]How to display 200 rows of data from CSV in this way '' line[0].split(';') "

如何顯示 CSV 中的 200 行數據? 我使用line[0].split(';')但它只顯示 1 行數據。

Test_X = []
with open('data testing 2.csv', 'r', encoding="utf-8") as f:
    reader = csv.reader(f, delimiter='\t')
    for i, line in enumerate(reader):
        tweet = line[0].split(';')

cleaning2 = cleaning(Test_X)
stemming2 = stemming(cleaning2)
tokenizing2 = tokenizing(stemming2)
stopwordremoval2 = stopwordremoval(tokenizing2)
fit_sw2 = fit_sw(stopwordremoval2)
count_vect2 = count_vect.transform([fit_sw2])
tf_idf2 = tf_idf.transform(count_vect2)

hasilpred_svm = model_svm.predict(tf_idf2)
with open('Hasil Testing SVM.csv', 'a', newline='') as f:
    writer = csv.writer(f)
    writer.writerow([fit_sw2, hasilpred_svm])

hasilpred_nb = model_nb.predict(tf_idf2)
with open('Hasil Testing NB.csv', 'a', newline='') as f:
    writer = csv.writer(f)
    writer.writerow([fit_sw2, hasilpred_nb])

這是輸出:

輸出

CSV 文件:

CSV 文件

您應該首先閱讀文件的所有行。 喜歡..

with open('data testing 2.csv', 'r') as read_obj:
    # pass the file object to reader() to get the reader object
    csv_reader = reader(read_obj)
    # Iterate over each row in the csv using reader object
    for row in csv_reader:
        # row variable is a list that represents a row in csv
        print(row)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM