This question is motivated by an answer I gave a while ago.
Let\'s say I have a dataframe like this
import numpy as np
import pandas as pd
df = pd.D
In the first case you are using the numpy max
function, which is aware of how to handle numpy.nan
.
In the second case you are using the builtin max
function from python. This is not aware of how to handle numpy.nan
. Presumably this effect is due to the fact that any comparison (>, <, == etc.) of numpy.nan
with a float leads to False. An obvious way to implement max
would be to iterate the iterable (the row in this case) and check if each value is larger than the previous, and store it as the maximum value if so. Since this larger than comparison will always be False when one of the compared values is numpy.nan
, whether the recorded maximum is the number you want or numpy.nan
depends entirely on whether the first value is numpy.nan
or not.