Puzzle 2 In or Out?
Pandas Brain Teasers — by Miki Tebeka (10 / 34)
👈 Rectified | TOC | Month by Month 👉
import pandas as pd
simpsons = pd.Series(
['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie'])
print('Bart' in simpsons)
Guess the Output
IMPORTANT
Try to guess what the output is before moving to the next page.
This code will print: False
pandas.Series is a sequence type. Most Python sequences are indexed by a range, meaning the first item is at index 0, the second item is at index 1, and so forth.
0 vs. 1
INFORMATION
Python is a 0-based language. Some languages, such as MATLAB, are 1-based. The compromise to use ½ as the first index didn’t go well. :)
pandas.Series (and pandas.DataFrame) indices are more flexible. The default is a range-based index, but there are other types of indices.
In [1]: import pandas as pd
In [2]…