Answers for "convert a column into binary"

0

convert a column into binary

data.Gender[data.Gender == 'male'] = 1
data.Gender[data.Gender == 'female'] = 0
print(data)
Posted by: Guest on March-24-2021
0

convert a column into binary

import pandas as pd

file = open("your.csv", "r")

data = pd.read_csv(file, sep = ",")

gender = {'male': 1,'female': 0}

data.Gender = [gender[item] for item in data.Gender]
print(data)
Posted by: Guest on March-24-2021

Code answers related to "convert a column into binary"

Browse Popular Code Answers by Language