Fügen Sie einen Link in eine Pandas-Tabelle ein

Ich möchte einen Link (zu einer Webseite) in eine Pandas-Tabelle einfügen. Wenn er in ipython notebook angezeigt wird, kann ich auf den Link klicken.

Ich habe folgendes versucht:

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

Die URL wird jedoch nur als Text angezeigt.

Ich habe auch versucht, ipython HTML-Objekt zu verwenden:

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  <IPython.core.display.HTML object at 0x0481E530>
1  1  <IPython.core.display.HTML object at 0x0481E770>
2  2  <IPython.core.display.HTML object at 0x0481E7B0>
3  3  <IPython.core.display.HTML object at 0x0481E810>
4  4  <IPython.core.display.HTML object at 0x0481EA70>

Es wird jedoch nur die Repräsentation des Objekts angezeigt.

Irgendwelche anderen Ideen?

BEARBEITEN: alko hat die richtige Antwort bekommen, wollte nur hinzufügen, dass die Zellenbreite standardmäßig begrenzt ist und langer HTML-Code abgeschnitten wird, dh:

<a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0">xxx</a>

wird dies werden:

<a href="aaaaaaaaaaaaaaaaaaaaaa...

und werden nicht korrekt angezeigt. (obwohl der Text xxx kurz ist und in die Zelle passen kann)

Ich habe es umgangen, indem ich Folgendes eingestellt habe:

pd.set_printoptions(max_colwidth=-1)

Antworten auf die Frage(1)

Ihre Antwort auf die Frage