Puzzle 6 Full of It

Pandas Brain Teasers — by Miki Tebeka (14 / 34)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Let’s Get Schwifty | TOC | A Delicious Div Sum 👉

empty.py

​ ​import​ ​pandas​ ​as​ ​pd​

​ s = pd.Series([], dtype=​'float64'​)
​ ​print​(​'full'​ ​if​ s.all() ​else​ ​'empty'​)

Guess the Output

IMPORTANT

Try to guess what the output is before moving to the next page.

images/hline.png

This code will print: full

images/hline.png

The pandas.Series.all documentation says the following:

Return whether all elements are True, potentially over an axis.

Returns True unless there is at least one element within a series or along a DataFrame axis that is False or equivalent (e.g., zero or empty).

The second paragraph explains what we see. There are no False elements in the empty series. The built-in all function behaves the same:

​ In [1]: all([])
​ Out[1]: True

all is like the mathematical ∀ (for all) symbol. Here’s what Wikipedia says:

By convention, the

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.