I have a df with an "isbn13" column. I also have a function called "isbnlib.meta". This function is from the library isbnlib. I would like to run the function on each row of the "isbn13" column. I'm using the apply function to do that.
df['publisher'] = df['isbn13'].apply(isbnlib.meta)
The issue is that the results for each isbn13 is a dictionary with various points such as Title, Author, Publisher, etc. I'm only looking for the "Publisher" result in the dictionary to be written out in my dataframe.
How do I only return the "Publisher" result in the dataframe from the dictionary results of the function?
Thank you in advance.
I suppose your
isbnlib.meta()
returns a dictionary based on the value in yourisbn13
column. If so, you can use a lambda function in the sameapply
:In this case, if your
dict
doesn't have aPublisher
key, it will return the default valueNone
.