I'd do it like this:
def _load_data_set(self, dataset_file):
df = pandas.read_csv(dataset_file, index_col=0)
return [PatientDataSet(first, rest.tolist()) for first, rest in df.iterrows()]
Passing index_col=0
to read_csv()
naturally separates the first column from the rest.
iterrows()
gives you the index and the values for each row, which is exactly what you need.
You may be able to remove .tolist()
if your PatientDataSet
does not actually need a list
but can accept rest
directly as a Pandas Series. That would be better, to avoid an unnecessary conversion.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…