I want to read last line of temperature (i.e. 24.925). My data is in following format in .csv format
Date Temp RH
2020-12-07 14:00:00 24.5198601667 66.9861108333
2020-12-07 15:00:00 24.9940271667 64.4736103333
2020-12-07 16:00:00 24.925 65
I'm following the given code:
from collections import deque
import csv
def get_last_row(csv_filename):
with open(csv_filename, 'rb') as f:
return deque(csv.reader(f), 1)[0]
lastline = ', '.join(get_last_row('data.csv'))
values = lastline.split("\t")
print ((values[1]))
Any suggestions will be helpful. Thank you in Advance.
get_last_row("data.csv")[1]. The CSV module would have split the columns out for you. No need for the tab splitting part. If its a tab separated file, thencsv.reader(f, dialect=csv.excel_tab)may work. But the data you've shown us is some sort of expanded view of the data - perhaps what you'd get from displaying a pandas data frame. Can you post the actual CSV file content?