add hyperlink to excel sheet created by pandas dataframe to_excel method

后端 未结 5 1602
栀梦
栀梦 2020-12-15 11:56

I have converted a pandas DataFrame to an Excel sheet using df.to_excel.

Now, I want to add hyperlinks to the values in one column. In other words, when a customer

5条回答
  •  醉酒成梦
    2020-12-15 12:04

    From @maxymoo's answer, here is a full example

    import pandas as pd
    df = pd.DataFrame({'Year': [2000, 2001, 2002 , 2003]})
    df['link'] = '-'
    df.set_value(0, 'link', '=HYPERLINK("https://en.wikipedia.org/wiki/2000", 2000)')
    df.set_value(1, 'link', '=HYPERLINK("https://en.wikipedia.org/wiki/2001", 2001)')
    df.set_value(2, 'link', '=HYPERLINK("https://en.wikipedia.org/wiki/2002", 2002)')
    df.set_value(3, 'link', '=HYPERLINK("https://en.wikipedia.org/wiki/2003", 2003)')
    df.to_excel('test.xlsx', index = False)
    

提交回复
热议问题