+ 1

Python Pandas

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

17th Jun 2020, 4:59 AM
Aditya Krishnan Mohan
Aditya Krishnan Mohan - avatar
2 Antworten
+ 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.
17th Jun 2020, 5:11 AM
Gordon
Gordon - avatar
+ 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]
17th Jun 2020, 5:13 AM
JME