Patients Temperatures¶
Let’s consider files that record the body temperatures for a number of respiratory diseases patients (which b.t.w. has been this year’s Marató de TV theme).
The info in the files has the following format:
each line of the file corresponds to a patient and contains the following data fields separated by coma (','):
The file patients.csv is an example:
38.6,Blanca-Nieves-Frias,37.6,38.2,38.8,38.9,38.9,39.0 37.1,Pere-Gil-Julivert,36.5,36.6,36.5,36.8,36.5,37.5 36.8,Mar-Tellez-Querdat,36.7,36.5,36.9,37.5,36.2 38.6,Lola-Marsa-Lada,39.4,38.9,39.0,39.1,38.3,37.1 37.4,Enric-Marco-Gol,37.0,37.3,38.4,38.9,36.6,35.9 37.7,Jordi-Torres-Pipes,38.2,38.1,37.5,36.8,36.5 37.7,Dolores-Fuertes-deCabeza,38.2,38.1,39.0,36.5,36.8 38.6,Ricard-Lamata-Feliz,39.4,38.9,39.0,39.1,39.3,37.1 37.5,Inmaculada-Delano-Moreno,36.9,36.5,36.8,37.5,38.5,38.9 37.4,Aitor-Menta-Morena,38.8,38.2,38.1,36.5,36.8,35.9
We need to filter the temperatures below a given threshold. Specificly, we need a new file with the same info, order and format of the given patients file but:
The temperatures below the threshold must be deleted.
The average temperatures must be recalculated accordingly.
The patiens with all temperatures below the threshold must be deleted.
To this purpose please implement the following Python function in the module pat_temp (file pat_temp.py):
The first function is:
- filter_pat_temp(fn, fnout, tempth)¶
such that
given
does two things:
writes a file named
fnoutresulting from filtering the temperatures by the thresholdtempthin the way described above.returns an
intwith the number of patients in the output file.
For example the call filter_pat_temp('patients.csv', 'patients-380.csv', 38.0) should return 8 and write a file called 'patients-380.csv' with the following info:
38.8,Blanca-Nieves-Frias,38.2,38.8,38.9,38.9,39.0 38.9,Lola-Marsa-Lada,39.4,38.9,39.0,39.1,38.3 38.6,Enric-Marco-Gol,38.4,38.9 38.2,Jordi-Torres-Pipes,38.2,38.1 38.4,Dolores-Fuertes-deCabeza,38.2,38.1,39.0 39.1,Ricard-Lamata-Feliz,39.4,38.9,39.0,39.1,39.3 38.7,Inmaculada-Delano-Moreno,38.5,38.9 38.4,Aitor-Menta-Morena,38.8,38.2,38.1
Doctests are available at the filter_pat_temp.test file
and the files used in those tests area available at
patients-380.ref,
patients-390.ref,
patients-393.ref,
patients-395.ref.
Note
To implement this function is recommended (but not mandatory) to previosly implement, test and call the following auxiliar functions:
The first function would be:
The second function would be: