KeyError в / Рекомендации / 'Расческа' - PullRequest
0 голосов
/ 24 апреля 2020

Я изменил все ошибки в моем коде, поэтому он показывает ошибку в [comb], когда я упомянул во всех местах, где мне нужно назначить

    Traceback:

    File "E:\FinalYearProject\movierecommendationsystem\myapps\views.py" in recomend
      65.df.head()

    During handling of the above exception (local variable 'df' referenced before assignment), another exception occurred:

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py" in get_loc
      2890.                 return self._engine.get_loc(key)

    File "pandas\_libs\index.pyx" in pandas._libs.index.IndexEngine.get_loc
      107. <source code not available>

    File "pandas\_libs\index.pyx" in pandas._libs.index.IndexEngine.get_loc
      131. <source code not available>

    File "pandas\_libs\hashtable_class_helper.pxi" in pandas._libs.hashtable.PyObjectHashTable.get_item
      1607. <source code not available>

    File "pandas\_libs\hashtable_class_helper.pxi" in pandas._libs.hashtable.PyObjectHashTable.get_item
      1614. <source code not available>

    During handling of the above exception ('comb'), another exception occurred:

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
      34.response = get_response(request)

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
      115. response = self.process_exception_by_middleware(e, request)

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
      113. response = wrapped_callback(request, *callback_args, **callback_kwargs)

    File "E:\FinalYearProject\movierecommendationsystem\myapps\views.py" in recommendation
      102. movies = recomend(movie)

    File "E:\FinalYearProject\movierecommendationsystem\myapps\views.py" in recomend
      68. df, sim = create_sim()

    File "E:\FinalYearProject\movierecommendationsystem\myapps\views.py" in create_sim
      54.count_matrix = cv.fit_transform(df['comb'])

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py" in __getitem__
      2975. indexer = self.columns.get_loc(key)

    File "C:\Users\Najuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py" in get_loc
      2892.                 return self._engine.get_loc(self._maybe_cast_indexer(key))

    File "pandas\_libs\index.pyx" in pandas._libs.index.IndexEngine.get_loc
    107. <source code not available>

    File "pandas\_libs\index.pyx" in pandas._libs.index.IndexEngine.get_loc
    131. <source code not available>

    File "pandas\_libs\hashtable_class_helper.pxi" in pandas._libs.hashtable.PyObjectHashTable.get_item
      1607. <source code not available>

    File "pandas\_libs\hashtable_class_helper.pxi" in pandas._libs.hashtable.PyObjectHashTable.get_item
     1614. <source code not available>

    Exception Type: KeyError at /recommendation/
    Exception Value: 'comb'

my views.py, где я также упомянул [гребень]

def create_sim():
  cv = CountVectorizer()
  count_matrix = cv.fit_transform(df['comb'])

Это моя ошибка показа ключа при рекомендации

def recommendation(request):
    if request.method == 'POST':
     movie = request.POST['movie']
     movies = recomend(movie)
     movie = movie.upper()
     print("here is your movies ", movie)
    if type(movies) == type('string'):
         return HttpResponse('recommend.html', movie=movie, movies=movies, t='s')
      else:
          return HttpResponse('recommend.html', movie=movie, movies=movies, t='scores')
     return render(request, 'recommend.html')

Mycreate.py

df = pd.read_csv('movie_dataset.csv')
df['comb'] = df['cast'] + ' ' + df['keywords'] + ' ' + df['genres'] + ''+ df['director']
cv = CountVectorizer()
count_matrix = cv.fit_transform(df['comb'])
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...