C3-W4: Exercise 5: use of series.sum()

Hello,

I’m having trouble calculating the value of ‘x’ for ex5 using sum as a panda function. I am getting an Index Error: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Any help?

1 Like

Hi!

It looks like the value that you are using to access some numpy array (one value inside [ ]) is not integer, slice or ellipsis. You need to check if you are not passing another type, such as another array, or a string.

Cheers,
Lucas

1 Like

for this same exercise I’m getting an error as ‘NameError: name ‘x’ is not defined’ even though in the previous cell data class consists this variable. can anyone help?

1 Like

Hi Priyanka, please let me know whether I’ve correctly diagnosed your problem. The x, n, and p variables arguments are wrapped inside of the estimation_metrics_pop() function. In other words, the x and n variables cannot be recalled to calculate the p variable, and instead need to be re-calculated once again.

3 Likes

I struggled with this issue about three days.:rage:
Thanks Tom. So many Thanks.

2 Likes

Hello everyone, I am getting the same
NameError: name ‘x’ is not defined error. Basically I am summing the input data array as:
x=data.sum()

The data array contains 1s and 0s so simply summing it would return the number of users, correct?

Why is x not defined?

1 Like

@Tom_Pham duh! i figured it out. both x and p need to be recalced as you mentioned above!

2 Likes

Thank you, Tom_Pham. Your explanation is really helpful.