Why is dataframe.sum(axis=0) getting NAN's when every value in every column is a real number?

Viewed 20

All column values in the selected measure_cols of the dfm DataFrame are real numbers - in fact all are between [-1.0..1.0] inclusive.

Following gives False for all Series/Columns in the dfc dataframe

[print(f"{c}: {dfc[c].hasnans}") for c in dfc.columns]

Results: all False

But all row sums in dfc['shap_sum'] are coming up as NAN's. Why would this be?

dfc['shap_sum'] = dfc[measure_cols].sum(axis=0)

enter image description here

Update The following has the correct results - as seen in the debugger

dfc[measure_cols].sum(axis=0)

But when assigned to a new column in the dataframe they get distorted into NaN's.

enter image description here

Why is this happening ?

dfc['shap_sum'] = dfc[measure_cols].sum(axis=0)

enter image description here

1 Answers

Oh I made the mistake of using axis=0 intending to do row sums. But it's axis=1 to do row sums. I will never agree with that decision on polarity.

Related