我有一個如下所示的輸入csv文件,我只想打印最近的8個條目..任何人都可以提供有關如何執行此操作的輸入信息?僅打印.csv文件中的最後8個條目
INPUT:-
trend.csv
['2013-06-25 20:01', '10']
['2013-06-25 20:06', '9']
['2013-06-25 20:06', '8']
['2013-06-26 20:06', '7']
['2013-06-26 20:06', '6']
['2013-06-26 20:06', '5']
['2013-06-26 20:06', '4']
['2013-06-26 20:06', '3']
['2013-06-26 20:06', '2']
['2013-06-26 20:08', '1']
OUTPUT:-
['2013-06-25 20:06', '8']
['2013-06-26 20:06', '7']
['2013-06-26 20:06', '6']
['2013-06-26 20:06', '5']
['2013-06-26 20:06', '4']
['2013-06-26 20:06', '3']
['2013-06-26 20:06', '2']
['2013-06-26 20:08', '1']
代碼:
import csv
#Now read the recent 8 entries and print
cr = csv.reader(open("trend.csv","rb"))
for row in cr:
#print only the recent most 8 entries
print row
你嘗試存儲8項? –
@ IgnacioVazquez-Abrams - 我只想存儲8個條目..bot確定如何做到這一點雖然..任何輸入? – user2341103
@ IgnacioVazquez-Abrams - 我得到一個錯誤文件「database.py」,第17行,在 last8 = collections.deque(maxlength = 8) TypeError:'maxlength'是這個函數的無效關鍵字參數 –
user2341103