Issue
I am currently working with the following data.
import pandas as pd
import io
csv_data = '''
gender,age,Cr,eGFR
1,76,0.56,60.7
1,50,0.76, 70.6
2,64,0.62,55.9
1,62,0.45,Nan
1,68,0.88,80.2
2,69,0.65,Nan
1,70,0.64,62.8
2,65,0.39,60.2
'''
df = pd.read_csv(io.StringIO(csv_data))
gender = 1 is male and 2 is female. This time, there are two missing values.
If it is a male:
eGFR = 194 × Cr - 1.094 × age - 0.287
If female:
eGFR = 194 × Cr - 1.094 × age - 0.287 × 0.739
I want to fill in the missing values as indicated above.
Solution
Few notes: Gender values are 1 and 2. I assumed 1=male and 2=female. There are Nan strings which are not NaN values.
# replace female value by its multiplier of the filling function
df['eGFR'] = df.eGFR.replace('Nan', pd.NA).fillna(194 * df.Cr - 1.094 * df.age - 0.287 * df.gender.where(lambda x: x==1, 0.739)).astype(float)
df
Answered By - not a robot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.