[英]Iterate dataframe and assign value to each row- I get the same value while I want different ones
I'm using the library isbntools to assign book titles to isbns.我正在使用图书馆 isbntools 将书名分配给 isbns。 From a dataframe that has isbns, I want to create a column named title and assign the title to the corresponding isbn.从具有 isbn 的 dataframe,我想创建一个名为 title 的列并将标题分配给相应的 isbn。 Problem is I get the same title.问题是我得到了相同的标题。
Example dataframe:示例 dataframe:
isbn
01234567
Desidred output所需 output
isbn, title
01234567, Curious George
isbn, title
01234567, Curious George
Code:代码:
from isbntools.app import *
for i in range(len(df_all['isbn'])):
for isbnz in df_all['isbn']:
meta_dict = meta(isbnz, service='goob')
title = meta_dict['Title']
df_all.iloc[i, df['Title'][i]]
I tried with iloc but it seems it didn't work我试过 iloc 但它似乎没有用
Use:利用:
# isbnlib is already installed as a dependency of isbntools
import isbnlib
def get_title(isbn):
try:
return isbnlib.meta(isbn)['Title']
except isbnlib.NotValidISBNError:
return None
df['Title'] = df['isbn'].astype(str).map(get_title)
>>> df
isbn Title
0 01234567 None
1 9780007525546 The Lord Of The Rings
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.