以下のような入力 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