Home > Back-end >  How to convert object to int in jupyter (pandas)?
How to convert object to int in jupyter (pandas)?

Time:05-23

How to convert object to int in jupyter (pandas)?

dataset['Gender'] = dataset['Gender'].astype(str).astype(int)

enter image description here

CodePudding user response:

You have a couple of options, you can map the values using a dictionary or a can factorize all unique values.

dataset['Gender'].str.lower().map({'female':0, 'male':1}) # assuming you have only male and female.

dataset['Gender'] = dataset['Gender'].factorize()[0]

  • Related