0

when mapping target variable, 'diabetes' (False patient has no diabetes, True patient has diabetes) to 0 (False) and 1 (True). All of entries come back as NaNs

I thought may be 'diabetes' isn't a true str and I need to convert to string first. Tried the following code:

diab_data['diabetes'] = diab_data['diabetes'].astype(str)

diab_data["diabetes"] = diab_data["diabetes"].map({'False':0, 'True':1})

I need values below to be either 0 (False) or 1 (True). All values return as NaN

Original Output:

patient diabetes
0         False
1         True
2         True 
3         True
4         False

Output after mapping:

patient diabetes
0         NaN
1         NaN
2         NaN
3         NaN
4         NaN
anky
  • 74,114
  • 11
  • 41
  • 70
arnorian
  • 13
  • 2

1 Answers1

1

You dont need map for this:

diab_data["diabetes"].astype(int)

Also you are using the bool values as string , use True instead of 'True' for example under map():

df["diabetes"].map({False:0, True:1})
anky
  • 74,114
  • 11
  • 41
  • 70
  • 1
    That worked thank you. Yea I did not need to put '' or "" around values for the variables as they are boolean values. That was the culprit – arnorian May 26 '19 at 06:24