print('http://google.com')
outputs a clickable url.
How do I get clickable URLs for pd.DataFrame(['http://google.com', 'http://duckduckgo.com'])
?
link() method in Python is used to create a hard link. This method creates a hard link pointing to the source named destination.
In this short guide, you'll see two different methods to create Pandas DataFrame: By typing the values in Python itself to create the DataFrame. By importing the values from a file (such as a CSV file), and then creating the DataFrame in Python based on the values imported.
If you print a URL to the console, it will get underlined if you hover over it, and if you right-click on it a menu pops up, and one of the menu options is "Open link". You just print it syntactically correct. To identify the hyperlink is the job of the terminal application. – Klaus D.
If you want to apply URL formatting only to a single column, you can use:
data = [dict(name='Google', url='http://www.google.com'), dict(name='Stackoverflow', url='http://stackoverflow.com')] df = pd.DataFrame(data) def make_clickable(val): # target _blank to open new window return '<a target="_blank" href="{}">{}</a>'.format(val, val) df.style.format({'url': make_clickable})
(PS: Unfortunately, I didn't have enough reputation to post this as a comment to @Abdou's post)
Try using pd.DataFrame.style.format
for this:
df = pd.DataFrame(['http://google.com', 'http://duckduckgo.com']) def make_clickable(val): return '<a href="{}">{}</a>'.format(val,val) df.style.format(make_clickable)
I hope this proves useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With