Puzzle 19 Holding out for a Hero
Pandas Brain Teasers — by Miki Tebeka (27 / 34)
👈 Off with Their NaNs | TOC | It’s a Date! 👉
import pandas as pd
heros = pd.Series(['Batman', 'Wonder Woman', 'Superman'])
if heros.str.find('Iron Man').any():
print('Wrong universe')
else:
print('DC')
Guess the Output
IMPORTANT
Try to guess what the output is before moving to the next page.
This code will print: Wrong universe
The str.find documentation says the following:
Return the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.
In the Puzzle 1, Rectified puzzle, we saw that, except for zeros, all numbers’ Boolean values are True.
When you run
In [1]: heros.str.find('Iron Man')
Out[1]:
0 -1
1 -1
2 -1
dtype: int64