0
max 함수 및 해당 키 인수를 사용하여 실제 영화 제목에서 근사 영화 제목과 가장 가까운 일치 항목을 찾으려고합니다. 내가 샘플 목록을 정의하고 작동 기능을 테스트하는 경우 ... TypeError : 'float'객체가 최대 내장 함수의 목록에서 반복 가능하지 않습니다.
from difflib import SequenceMatcher as SM
movies = ['fake movie title', 'faker movie title', 'shaun died']
approx_title = 'Shaun of the Dead.'
max(movies, key = lambda title: SM(None, approx_title, title).ratio())
'shaun died'
는하지만 별도의 dataframe에서 전체 열을 일치하도록 노력하고, 그래서 팬더 시리즈 그 목록과 실행에 전환 시도 같은 기능이지만, 대신에 비록 내가 두 영화의 데이터 유형을 확인 했는데도 type_error를 얻었습니다 & movie_lst는 목록입니다.
Old id New id Title Year Critics Score Audience Score Rating
NaN 21736.0 Peter Pan 1999.0 NaN 70.0 PG nothing objectionable
NaN 771471359.0 Dragonheart Battle for the Heartfire 2017.0 NaN 50.0 PG13
NaN 770725090.0 The Nude Vampire Vampire nue, La 1974.0 NaN 24.0 NR
2281.0 19887.0 Beyond the Clouds 1995.0 65.0 67.0 NR
10913.0 11286.0 Wild America 1997.0 27.0 59.0 PG violence
movie_lst = rt_info['Title'].tolist()
['Peter Pan',
'Dragonheart Battle for the Heartfire',
'The Nude Vampire Vampire nue, La',
'Beyond the Clouds',
'Wild America',
'Sexual Dependency',
'Body Slam',
'Hatchet II',
'Lion of the Desert Omar Mukhtar',
'Imagine That',
'Harold',
'A United Kingdom',
'Violent City The FamilyCitt violenta',
'Ratchet Clank',
'Wes Craven Presents Carnival of Souls',
'The Adventures of Ociee Nash',
'Blackfish',
'For Petes Sake',
'Daybreakers',
'The Big One',
'Godzilla vs Megaguirus',
'In a Lonely Place',
'Case 39', ...
]
max(movie_lst, key = lambda title: SM(None, approx_title, title).ratio())
TypeError Traceback (most recent call last)
<ipython-input-88-0022a3c1bdb9> in <module>()
----> 1 max(movie_lst, key = lambda title: SM(None, approx_title, title).ratio())
<ipython-input-88-0022a3c1bdb9> in <lambda>(title)
----> 1 max(movie_lst, key = lambda title: SM(None, approx_title, title).ratio())
/usr/lib/python3.4/difflib.py in __init__(self, isjunk, a, b, autojunk)
211 self.a = self.b = None
212 self.autojunk = autojunk
--> 213 self.set_seqs(a, b)
214
215 def set_seqs(self, a, b):
/usr/lib/python3.4/difflib.py in set_seqs(self, a, b)
223
224 self.set_seq1(a)
--> 225 self.set_seq2(b)
226
227 def set_seq1(self, a):
/usr/lib/python3.4/difflib.py in set_seq2(self, b)
277 self.matching_blocks = self.opcodes = None
278 self.fullbcount = None
--> 279 self.__chain_b()
280
281 # For each element x in b, set b2j[x] to a list of the indices in
/usr/lib/python3.4/difflib.py in __chain_b(self)
309 self.b2j = b2j = {}
310
--> 311 for i, elt in enumerate(b):
312 indices = b2j.setdefault(elt, [])
313 indices.append(i)
TypeError: 'float' object is not iterable
나는 왜 - 모든 도움을 주시면 감사하겠습니다!
당신이'movie_lst' 인쇄 시도 : 당신이 인쇄하여 범죄자를 찾을 수 있습니다
노트? 당신이 하나의 컬럼을 벗어나고 캐릭터 대신에 플로트를 반복 할 가능성이 매우 높습니다. –
예, movie_lst의 모양을 보여주기 위해 질문을 업데이트했습니다. – Matt
야생 추측 : 플로트와 같은 이름의 영화가 없습니까? 나는 11.6이라고 불리는 프랑스 사람을 안다. 팬더가 자동으로 플로트로 변환하지 않겠습니까? –