Try to search your question here, if you can't find : Ask Any Question Now ?

Why doesn't this code loop through a Series and replace values?

HomeCategory: stackoverflowWhy doesn't this code loop through a Series and replace values?
willson asked 2 weeks ago
# data is a dataframe
for i in data.Sex[0:]:
    if i == 'male':
        i=1
        print(i)
    elif i == 'female':
        i=0
        print(i)

The output prints the column in what I intended it to be, changing male to 1 and female to 0. However, the i=1 and i=0 seemed to not have worked. If I run

print(data.Sex)

then nothing changed

1 Answers
Best Answer
Amit answered 2 weeks ago
Your Answer

9 + 2 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com