Python Pandas | Sololearn: Learn to code for FREE!


Python Pandas

Can someone please explain what this code means: df['male'] = df['Sex'] == 'male'

6/17/2020 4:59:49 AM

Aditya Krishnan Mohan

2 Answers

New Answer


comparison is evaluated first. If the Sex property of df is string male, the male property of df is set to boolean True, otherwise it's false.


df['Sex'] == 'male' returns a df the same shape as df['Sex'] where cells that have the value 'male' are set to True and other cells are set to false ['male','female','male'] == 'male' would return [True, False, True]