Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute name must be string, not 'int' || Typecaste to str as well #119

Open
rsurati opened this issue Nov 6, 2023 · 0 comments
Open

Comments

@rsurati
Copy link

rsurati commented Nov 6, 2023

TypeError Traceback (most recent call last)

Cell In[188], line 1, in (x)
----> 1 df['genres'] = df['Title'].map(lambda x: get_genre(str(x)))

Cell In[186], line 7, in get_genre(x)
5 result = tmdb_movie.search(x)
6 if ( len(result) != 0 ):
----> 7 movie_id = str(result[0]['id'])
8 response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key={}'.format(movie_id,tmdb.
9 data_json = response.json()

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\tmdbv3api\as_obj.py:47, in AsObj.getitem(self, key)
45 return self._obj_list[key]
46 else:
---> 47 return getattr(self, key)

TypeError: attribute name must be string, not 'int'

Here is the genre method:

from tmdbv3api import Movie
tmdb_movie = Movie()
def get_genre(x):
genres = []
result = tmdb_movie.search(x)
if ( len(result) != 0 ):
print(type(result[0]))
movie_id = str(result[0].id)
response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key={}'.format(movie_id,tmdb.api_key))
data_json = response.json()
if data_json['genres']:
genre_str = " "
for i in range(0,len(data_json['genres'])):
genres.append(data_json['genres'][i]['name'])
return genre_str.join(genres)
else:
np.NaN
else:
np.NaN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant