Why does max() sometimes return nan and sometimes ignores it?
问题 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.DataFrame({'a': [1, 2, np.nan], 'b': [3, np.nan, 10], 'c':[np.nan, 5, 34]}) a b c 0 1.0 3.0 NaN 1 2.0 NaN 5.0 2 NaN 10.0 34.0 and I want to replace the NaN by the maximum of the row, I can do df.apply(lambda row: row.fillna(row.max()), axis=1) which gives me the desired output a b c 0 1.0 3.0 3.0 1 2.0 5.0 5.0 2 34.0 10.0 34.0 When I, however, use