Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert a link inside a pandas table
    primarykey
    data
    text
    <p>I'd like to insert a link (to a web page) inside a pandas table, so when it is displayed in ipython notebook, I could press the link.</p> <p>I tried the following:</p> <pre><code>In [1]: import pandas as pd In [2]: df = pd.DataFrame(range(5), columns=['a']) In [3]: df['b'] = df['a'].apply(lambda x: 'http://example.com/{0}'.format(x)) In [4]: df Out[4]: a b 0 0 http://example.com/0 1 1 http://example.com/1 2 2 http://example.com/2 3 3 http://example.com/3 4 4 http://example.com/4 </code></pre> <p>but the url is just displayed as text. </p> <p>I also tried using ipython HTML object:</p> <pre><code>In [5]: from IPython.display import HTML In [6]: df['b'] = df['a'].apply(lambda x:HTML('http://example.com/{0}'.format(x))) In [7]: df Out[7]: a b 0 0 &lt;IPython.core.display.HTML object at 0x0481E530&gt; 1 1 &lt;IPython.core.display.HTML object at 0x0481E770&gt; 2 2 &lt;IPython.core.display.HTML object at 0x0481E7B0&gt; 3 3 &lt;IPython.core.display.HTML object at 0x0481E810&gt; 4 4 &lt;IPython.core.display.HTML object at 0x0481EA70&gt; </code></pre> <p>but it will only display the repr of the object.</p> <p>Any other ideas?</p> <p>EDIT: alko got the right answer, just wanted to add that the cell width is limited by default, and long html code will be truncated, ie:</p> <pre><code>&lt;a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0"&gt;xxx&lt;/a&gt; </code></pre> <p>will become this:</p> <pre><code>&lt;a href="aaaaaaaaaaaaaaaaaaaaaa... </code></pre> <p>and won't be displayed correctly. (even though the text xxx is short and can fit in the cell)</p> <p>I've bypassed it by setting:</p> <pre><code>pd.set_printoptions(max_colwidth=-1) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload