csv.reader()
returns an iterator that yields an array of columns per iteration (i.e. line).
Simply put, this is sufficient to get you the first line of data.txt as a list:
import csv
with open ('data.txt') as f:
first_row = csv.reader(f, delimiter='\t')
It appears you also want to convert the list elements to a decimal type, which can be done using map(...)
and float(...)
.
e.g.:
first_row = map(float, first_row)
If the list contains the text "NaN", float()
converts this to the special value nan
without much intervention.
e.g.:
>>> float("NaN")
nan