【问题标题】:how to get the vlaue from the from the dataframe that is mention in the list如何从列表中提到的数据框中获取值
【发布时间】:2021-06-16 07:26:05
【问题描述】:
  books=  ['When The Storm Breaks', 'When The Bough Breaks (Alex Delaware Novels (Paperback))', 'Storm Front (The Dresden Files, Book 1)', 'The Fellowship Of The Ring (The Lord Of The Rings, Part 1)', 'The Return Of The King (The Lord Of The Rings, Part 3)', 'The Sign Of The Beaver', 'The Fly On The Wall', 'The Cat In The Hat', 'The Member Of The Wedding']

这是我的列表,所以我试图从数据框中获取列表项图像,所以我尝试了以下代码:

def get_image(books):
    img=[]
    data = pd.read_csv('C:/Users/suhel/Desktop/book recommendation/file.csv')
    for i in range(len(books)):
       w=data.loc[data['title']==books[i],'Image']
       img.append(w) 
    return img   

但它只返回一个图片链接,其余如下:

    [Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object), 360    http://images.amazon.com/images/P/0451457811.0...
Name: Image, dtype: object, Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object), Series([], Name: Image, dtype: object)]

有没有办法从数据框中获取所有列出的图像链接,而不需要索引对象或 dtype

【问题讨论】:

    标签: python pandas dataframe series


    【解决方案1】:

    使用isin

    result = df[df['title'].isin(books)]['Image']
    

    【讨论】:

    • 我试过只显示一个图像链接 360 images.amazon.com/images/P/0451457811.0... 名称:图像,dtype:对象
    • 看看是否可以粘贴我们可以复制和执行的数据框本身。然后我们就可以找到问题的根源。同时发布该数据框的预期输出
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2021-05-17
    • 1970-01-01
    相关资源
    最近更新 更多