In: Computer Science
In [12]: pd.Series([1.0,np.NaN,5.9,6])+pd.Series([3,5,2,5.6]) Out[12]: 0 4.0 1 NaN 2 7.9 3 11.6 dtype: float64 In [13]: pd.Series([1.0,25.0,5.5,6])/pd.Series([3,np.NaN,2,5.6]) Out[13]: 0 0.333333 1 NaN 2 2.750000 3 1.071429 dtype: float64
What are they trying to explain here?
That pandas returns a missing value where one of the operands is missing
That pandas treats NaN values as zero, when an operation is performed
That pandas removes all records in which one of the operands is NaN
That the + and / operations in pandas are special cases in which the NaN values are treated as floats. The rest of the mathematical operations treat NaN values as strings.
CORRECT ANSWER EXPLANATION: "That pandas returns a missing value where one of the operands is missing": When adding 2 series in pandas, it returns NaN value if any of the operand is NaN.
Although, in the case of .sum() which returns the sum of the contents in a single series, then the NaN values are skipped.
WRONG ANSWER EXPLANATION: "That pandas treats NaN values as zero, when an operation is performed" is false because pandas always considers NaN as null when any of the operands are NaN.
WRONG ANSWER EXPLANATION: "That pandas removes all records in which one of the operands is NaN" : Pandas doesnt remove any record unless specified manually.
WRONG ANSWER EXPLANATION: "That the + and / operations in pandas are special cases in which the NaN values are treated as floats. The rest of the mathematical operations treat NaN values as strings." : All pandas objects treat NaN values as floats irrespective of the operation. When NaN operands are included in the operation, it returns NaN.