0

I am learning pandas and python,

I want to fetch more information about movies from IMDB library and save it in an addition column in my already existing data frame.

For example: df['titleId'] has movie IDS in my data frame (total almost 50-60)

(with the help of ImdbPy library), I want to create new column df['movie_name'] in same data frame to store movie names for that particular movie ID df['titleId']

I managed to do it with one value (not in data frame) but not able to handle it in dataframe. Please help.

Code to get movie name is as under:

#### YEAR OF THE MOVE

# importing the module
import imdb

# creating instance of IMDb
ia = imdb.IMDb()

# getting the movie with id
search = ia.get_movie("2082197")

# getting movie year
year = search['year']

# printing movie name and year
print(search['title'] + " : " + str(year))
sana ullah
  • 43
  • 3
  • Are you looking for [`Series.apply`](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) -> `df['movie_name'] = df['titleID'].apply(lambda x: ia.get_movie(x)['title'])`? [How can I use the apply() function for a single column?](https://stackoverflow.com/q/34962104/15497888) – Henry Ecker Oct 30 '21 at 19:33
  • 1
    @HenryEcker it worked ... thanks a lot for help. may you rise and shine :) – sana ullah Oct 31 '21 at 14:48
  • What warning are you getting? – Henry Ecker Oct 31 '21 at 14:51
  • @HenryEcker ... it worked fine but its giving a warning as well... (I know one should ignore them, but as a learner i want to know about it ...) i will really appriciate if you explain this wanring – sana ullah Oct 31 '21 at 14:52
  • @HenryEcker A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy – sana ullah Oct 31 '21 at 14:52
  • Okay so somewhere you've unsafely subset your DataFrame. [This answer](https://stackoverflow.com/a/53496996/15497888) explains somewhat about what's happening. [also here](https://stackoverflow.com/a/54914752/15497888) – Henry Ecker Oct 31 '21 at 14:54

1 Answers1

0

If I'm understanding you correctly, you are looking for merge.

As a toy example, if you have a dataframe A with columns (id, name) and another dataframe B with columns (id, year), you can do A.merge(B, how="left") to get a dataframe C with columns (id, name, year). Note that if B is much smaller than A (i.e., if there are ids in A that are not in B), then you can get nan values in C - you can explore other type of joins for this.

Juho
  • 976
  • 1
  • 13
  • 27