2

I am using Python 3 and below is my code which I am using to create clickable links once the data is returned from the data frame.

 #Create Clickable Link Value

df_linky = df_sorted
df_linky['Thread'] = df_sorted['Title'] + '#&#' + df_sorted['Link']
def make_clickable_both(val): 
    name, url = val.split('#&#')
    return f'<a href="{url}">{name}</a>'
df_compl = df_linky[['Thread','Score','Date Posted','Time Posted','Brand']]
df_complete = df_compl.reset_index(drop = True).set_index('Score')
df_complete = df_complete.style.format({'Thread': make_clickable_both})
return df_complete

I am getting an error in terminal

    return f'<a href="{url}">{name}</a>'
                                       ^
   SyntaxError: invalid syntax

And in the return value

429 {name}  2019-05-16  03:11   Smart Water 

At the place of "{name}" it should be the name of the link, can any one suggest what is going wrong with this, I am using pandas library.

Ammar
  • 1,305
  • 2
  • 11
  • 16
Piyush Patil
  • 14,512
  • 6
  • 35
  • 54

1 Answers1

2

You're using "f-string," which was introduced in Python 3.6.

You can either update your Python version to 3.6, or you can do it like this:

return '<a href="{}">{}</a>'.format(url, name)

You need Python 2.6 or above for this to work.

Or you can use this "Old-school" formatting that "has been in the language since the very beginning."

return '<a href="%s">%s</a>' % (url, name)
Amir Shabani
  • 3,857
  • 6
  • 30
  • 67