At the testing accuracy, I get 0.92.
When I run “Test your function” I get this error.
IndexError: single positional indexer is out-of-bounds
At the end of the get_accuracy function, I get i = 4950 and m = 4951.
I checked to see what i was on the last go around and it was 4950.
So I am lost as to the cause of the out of bounds.
I am using city1 = data.iloc[i][‘city1’] to get city1
That is what the error points to.
1442 len_axis = len(self.obj._get_axis(axis))
1443 if key >= len_axis or key < -len_axis:
→ 1444 raise IndexError(“single positional indexer is out-of-bounds”)
All tests pass up to this point.
Any idea as where I might check?
Thanks
Okay, I kept checking and changed iloc to loc.
FAIL on my part.
It works now.
Thanks
1 Like
Glad you got it. I noticed that if you print out the string returned for city1 in the graded function the last element is Zagreb
, but in the unit test it goes back to Kabul
. which is where the exception is thrown. I didn’t track down why yet and it seems overtaken by events so I won’t bother.
Not sure how you are implementing the guidance
# loop through the rows of the dataframe
One way is using pandas.DataFrame.iterrows()
which returns two objects. First is the index, i
, and second is the data of the row as a Series object. From which you can access a column as my_row[‘my_column’]. Seems more efficient to use the row directly provided by the iterator rather than do another lookup using the index, but I didn’t benchmark the two approaches. Certainly is easier to write and read. Cheers
I made it past this original post but got stuck at the same place as several others did, 4 passing and 2 failing tests with the wrong values.
I went to the thread where the others posted their same issue.
Should I create a new post or post to the thread?
https://community.deeplearning.ai/t/stuck-with-dimensions-on-compute-pca/68696/13
Thanks
Upon further reading in the Pandas doc, it looks to me like itertuples
is the right choice…
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.itertuples.html