Question

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]:...

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.

Solutions

Expert Solution

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.


Related Solutions

Rates of return on 24 mutual funds are shown. Fund 12-Mo. 5-Year 1 7.9 4.0 2...
Rates of return on 24 mutual funds are shown. Fund 12-Mo. 5-Year 1 7.9 4.0 2 2.9 3.4 3 14.2 7.9 4 5.5 9.8 5 5.1 6.9 6 10.2 12.1 7 3.7 7.8 8 7.8 11.4 9 10.4 15.1 10 12.6 5.5 11 10.0 9.4 12 13.4 2.7 13 -0.7 12.2 14 5.3 4.8 15 21.1 13.2 16 11.7 4.7 17 -1.8 6.4 18 -2.7 -2.7 19 13.7 8.3 20 11.2 8.5 21 8.9 5.0 22 0.9 6.2 23 1.2...
Alabama 3 3 1 0 1 1 0 0 0Alaska 57 39 12 2 1...
Alabama 3 3 1 0 1 1 0 0 0Alaska 57 39 12 2 1 24 7 8 3Arizona 278 171 128 4 3 36 42 55 10Arkansas 164 110 51 10 4 45 18 30 6California 1,861 1,275 855 34 33 353 263 233 90Colorado 176 115 65 12 6 32 25 19 17Connecticut 107 73 29 0 2 42 16 9 9Delaware 63 52 26 0 0 26 6 3 2District of Columbia 162 121 65 1 0...
0 0 2 0 5 3 1 12 0 0 0 1 6 0 1 1...
0 0 2 0 5 3 1 12 0 0 0 1 6 0 1 1 2 8 1 3 1 6 2 4 0 16 17 0 8 0 3 0 0 1 2 5 2 0 2 1 5 0 7 0 1 0 0 1 0 0 3 1 9 4 1 3 0 1 1 1 0 7 1 9 2 0 1 1 1 1 7 2 7 1 2 =============================== (a) What type of...
Cell x y Demand Fabrication 1.0 4.0 12 Paint 1.0 2.0 24 Subassembly 1 2.5 2.0...
Cell x y Demand Fabrication 1.0 4.0 12 Paint 1.0 2.0 24 Subassembly 1 2.5 2.0 13 Subassembly 2 3.0 5.0 7 Assembly 4.0 4.0 17 Let us consider again the data from the LaRosa tool bin location problem discussed in Section 14.3. Suppose we know the average number of daily trips made to the tool bin from each production station. The average number of trips per day are 12 for fabrication, 24 for Paint, 13 for Subassembly 1, 7...
first matrix A [ 2 -1 3 ] [-4 0 -2 ] [2 -5 12 ]...
first matrix A [ 2 -1 3 ] [-4 0 -2 ] [2 -5 12 ] [4 0 4 ] amd b [2] [-2] [5] [0] solve for Ax=b using tan LU factorization of A
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
The Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21 … begins with the...
The Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21 … begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms. Write a non-recursive function Fibonacci (n) that calculates the nth Fibonacci number. Write a program to display a table of terms and the Fibonacci number in two columns for the first 15 terms, using the function you created.
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13,...
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 . . . See the pattern? Each element in the series is the sum of the preceding two elements. Here is a recursive formula for calculating the nth number of the sequence: Fib(N) = {N, if N = 0 or 1 Fib(N - 2) + Fib(N - 1), if N > 1 a) Write a recursive method fibonacci that returns...
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)5 NUMBER SUMMARY – B.)BOX AND WHISKERS PLOT – C.) OUTLIERS-
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT