1

I got 3 columns in my dataframe.

Example:

name = ['iphone']
price = ['1000']
url = ['https://iphone.com/']
MY_DF = pd.DataFrame({'name': name, 'price':price})
MY_DF.to_excel('123.xlsx')

I need did it in loop in my dataframe.

How to apply url as hyperlink to price? and export it to xlsx result need to be like:

enter image description here

The methods described in this article: add hyperlink to excel sheet created by pandas dataframe to_excel method do not suit me.

In my situation every url is unique and I don't know how to right apply them for my 'price'.

Seems like this could work, but I don't know how to loop it:

enter image description here

Thank you in advance

4
  • Does this answer your question? add hyperlink to excel sheet created by pandas dataframe to_excel method Commented Oct 30, 2021 at 12:56
  • @HarryPlotter I don't think so Commented Oct 30, 2021 at 12:57
  • Please update your post with a sample of the DataFrame. It's not clear from the example how it's formated. Do you have 3 separate columns: product name, price and url? Commented Oct 30, 2021 at 17:16
  • @HarryPlotter i was find solution, see below. anyway thanks for your attention. Commented Oct 30, 2021 at 18:12

1 Answer 1

1
def make_hyperlink(value):
    url = "{}"
    return '=HYPERLINK("%s", "%s")' % (url.format(value).split(' ')[0], url.format(value).split(' ')[1])

Il combine my url and price as prices = 'urls' +' '+'price' append it to main dataframe as ['price'] and apply next myDF['price'] = myDF['price'].apply(lambda x: make_hyperlink(x)) and it works! =)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.