简体   繁体   中英

webbrowser.open on DataFrame entry

I have a pandas' DataFrame like this:

listings_df = pd.DataFrame({'prices': prices,
                            'listing_links': listing_links,
                            'photo_links': photo_links,
                            'listing_names': listing_names})

photo_links list contains URLs to photos. Say I want to get a link straight from the dataframe and open it in webbrowser like this:

link_to_open = listings_df.loc[1:1,'photo_links']
webbrowser.open(link_to_open)

However the link does not open and I get a 404 error, because the link is stored in the dataframe (or at least printed) in a shortened version:

https://a0.muscache.com/im/pictures/70976075/b

versus the original link as it is stored in the photo_links list:

https://a0.muscache.com/im/pictures/70976075/b20d9efc_original.jpg?aki_policy=large

The question is, how do I access full link from within dataframe?

link_to_open = listings_df.loc[1:1,'photo_links'] returns Series object.

try this

link_to_open = listings_df.loc[1,'photo_links']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM