I had a question where i needed to find how many people have the word "Chief" in their jobtitle? i was using the below two approaches but both of them give different answers, kindly let me know what's the difference and which should i use.
Approach 1:
len(sal[sal.JobTitle.str.contains("Chief", case=True, na=False)])
This gives output as 423
Approach 2:
count = 0
for job in sal['JobTitle']:
for j in job.split():
if j.lower() =='chief':
count+=1
print(count)
This gives the correct output 477.
case=Falsein the first code. Also, you might have rows with multiple occurrences of "chief" in the same string, you count them in the second approach, not the first