使用python逐行列印 csv檔案中的資料

2021-09-11 12:32:54 字數 854 閱讀 6777

前言最近想使用深度學習 做乙個廣告推薦系統,發現資料集的格式是.csv的, ok 想逐行列印csv中的資料集

發現python逐行列印資料集的時候,發現僅僅只能列印第一行的資料,下面一行怎麼都列印不了。 ok 現在分享一下解決方案。

原始資料集的形式是:

這樣讀取的時候 只能列印列印第一行的資料, 如果想列印下一行資料集的時候,只需要把讀出的資料集轉化成numpy的形式即可

我們發現能夠逐行列印了  但是第一行的關於產品資訊的資料又沒有了, 不管了 以後用的到再說吧

import pandas as pd

import numpy as np

path = '../dataset/dlnlp_dataset/one-thousand-commodity/'

tests= pd.read_csv(open(path + 'test.csv'))

print("**********type***********",type(tests))

print("**********len***********",len(tests))

print("**********資料是***********",tests)

np_tests = np.array(tests)

for i, test in enumerate(np_tests):

if i < 10:

print("第%d行的資料是%s:"%(i,test))

else:

break

使用setitimer逐行列印檔案

include include include include include include include char line bufsiz void hand int sig void put char filename while fgets line,bufsiz,fp null fclo...

Python基礎 逐行讀取檔案並列印

返回 python基礎 索引頁 下面的例子,讀取乙個名為 test.txt 的檔案內容,並逐行列印。test.txt 位於與我的python 程式同乙個目錄下,其內容為 this is line 1this is line 2 我的程式如下 myfile open test.txt line myf...

php 逐行讀取csv資料入庫

需求 把從execel檔案中匯出的csv資料,匯入資料庫 解決方案如下 判斷檔案是否上傳成功 if empty files file1 files file1 error 0 else 組裝資料 fields name age telephone fields cnt count fields 用二...