Issue
I have the following code:
if 0 in df[RATING_COL]:
rating_col_list = df[RATING_COL].to_list()
assert 0 in rating_col_list
The assert is triggering an AssertionError
. How can this be possible? How can it be that there's a 0 in the column, but when I convert the column to a list, the 0 disappears?
The dataframe I'm loading is based on MovieLens-1M and looks like:
user_id,item_id,rating
1,1193000,2
1,1193001,3
1,1193002,4
1,1193003,5
1,1193004,6
1,1193005,7
1,1193006,8
1,1193007,9
1,1193008,10
1,661000,6
1,661001,7
1,661002,8
1,661003,9
1,661004,10
1,661005,9
1,661006,8
1,661007,7
1,661008,6
In this format, 1,1193008,10
indicates that user 1 rated item 1193 with an 8. The 10 indicates that this is the rating, and all other items starting with 1193 will have a rating lower than 10. (So 1,661004,10
indicates that user 1 rated item 661 with a 4.)
(Also, I've checked with CTRL-F: there is no 0 rating in the rating column.)
Solution
0 in df[RATING_COL]
searches in the index, to search in the Series values use:
if 0 in df[RATING_COL].values:
rating_col_list = df[RATING_COL].to_list()
assert 0 in rating_col_list
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.