Is there a quick way to read the last N lines of a CSV file in Python, using numpy
or pandas
?
I cannot do skip_header
Use skiprows
parameter of pandas
read_csv()
, the tougher part is finding the number of lines in the csv. here's a possible solution:
with open('filename',"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
row_count = len(data)
df = pd.read_csv('filename', skiprows = row_count - N)