+ 1
Python Pandas
Can someone please explain what this code means: df['male'] = df['Sex'] == 'male'
2 Respuestas
+ 3
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.
+ 2
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]