Q:

I am getting error when i call function def because_you_watched error is sample() missing 1 required positional argument: 'k'

import random

def because_you_watched(user, user_item, users, movies, k=5, N=5):

    movieTableIDs = get_rated_movies_ids(user, user_item, users, movies)
    df = get_movies(movieTableIDs, movies_table)

    movieIDs = random.sample(list([df.movieId, N]))

    for movieID in movieIDs:
        title = df[df.movieId == movieID].iloc[0].title
        print("Because you've watched ", title)
        similar_and_display(movieID, movies_table, movies, k)

because_you_watched(500, user_item, users, movies, k=5, N=5)

A:

As is stated in Pawel's answer. The sample function of the random package takes two arguments and you only supply one as a list. Assuming the N parameter means number of samples you could try something like movieIDs = random.sample(list(df.movieId),N). Otherwise, why not just use the sample method of pandas' dataframe documented here.

DataFrame.sample(n=None, frac=None, replace=False, weights=None, random_state=None, axis=None)
Return a random sample of items from an axis of object.
n : int, optional
Number of items from axis to return. Cannot be used with frac. Default = 1 if frac = None.

Then you can just do sample = list(df.sample(n=N).movieId) I think.

