我在网络驱动器上的.csv
个文件中存储了数千个时间序列。在更新文件之前,我首先获取文件的最后一行以查看时间戳,然后在该时间戳之后更新数据。如何通过网络驱动器快速获取.csv
文件的最后一行,以便我不必仅加载整个巨大的.csv
文件以使用最后一行?
答案 0 :(得分:3)
假设您使用内置的reversed
模块,有一个漂亮的csv
工具:
how to read a csv file in reverse order in python
简而言之:
import csv
with open('some_file.csv', 'r') as f:
for row in reversed(list(csv.reader(f))):
print(', '.join(row))
在我的测试文件中:
1: test, 1
2: test, 2
3: test, 3
输出:
test, 3
test, 2
test, 1