작성
·
251
0
place_simi_co = ( place_simi_cate * 1 )
place_simi_co_sorted_ind = place_simi_co.argsort()[:, ::-1]
def find_simi_place(df, sorted_ind, place_name, top_n=10):
place_title = df[df['name'] == place_name]
place_index = place_title.index.values
similar_indexes = sorted_ind[place_index, :(top_n)]
similar_indexes = similar_indexes.reshape(-1)
return df.iloc[similar_indexes]
find_simi_place(df, place_simi_co_sorted_ind, '버터로니아', 5)
를 실행시켰더니 이렇게 오류가 떠요..! TypeError: type 'DataFrame' is not subscriptable라는 오류는 인터넷에 아무리 찾아봐도 안나와서요ㅠㅠ DataFrame에 대한 오류가 왜 뜨는건지 간단하게라도 알려주실 수 있을까요..??
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[77], line 1
----> 1 find_simi_place(df, place_simi_co_sorted_ind, '버터로니아', 5)
Cell In[76], line 17, in find_simi_place(df, sorted_ind, place_name, top_n)
15 def find_simi_place(df, sorted_ind, place_name, top_n=10):
---> 17 place_title = df[df['name'] == place_name]
18 place_index = place_title.index.values
19 similar_indexes = sorted_ind[place_index, :(top_n)]
TypeError: type 'DataFrame' is not subscriptable
답변 1
0
안녕하세요 pghniau 님, 인프런 AI 인턴이에요.
해당 코드를 실행할 때 발생한 오류는 ‘TypeError: type ‘DataFrame’ is not subscriptable’ 입니다. 이 오류는 DataFrame 객체에 대해 인덱싱 연산을 적용할 때 발생하는 문제입니다.
가능한 원인은 다음과 같습니다:
1. df 변수가 DataFrame 객체가 아닌 다른 타입의 객체로 잘못 정의되어 있는 경우
2. df 객체의 ‘name’ 컬럼이 존재하지 않는 경우
3. df 객체의 인덱스가 숫자로 구성된 정수 인덱스가 아닌 경우
4. 다른 이유로 인해 df 객체가 올바르게 로드되지 않은 경우
오류 해결을 위해 다음 사항들을 확인해보세요:
1. 코드 실행 전에 df 객체가 DataFrame으로 올바르게 정의되어 있는지 확인해보세요.
2. ‘name’ 컬럼이 df 객체에 존재하는지 확인해보세요.
3. df 객체의 인덱스가 숫자로 구성된 정수 인덱스인지 확인해보세요.
4. df 객체가 올바르게 로드되었는지 다시 확인해보세요.
만약 위의 방법들을 시도해도 문제를 해결할 수 없다면, 해당 코드와 함께 더 많은 정보를 제공해주시면 더 자세한 도움을 드릴 수 있습니다. 감사합니다.