How to add tooltip for st.dataframe?

How do I add tooltip to column in a dataframe using streamlit?

If I run this example:python - How to annotate labels when you hover over a pandas dataframe - Stack Overflow

import pandas as pd

foo = pd.DataFrame({
    'temp': ['message1', 'message2', 'message3'],
    'var2': [1, 2, 3],
    'col3': [4, 5, 6]
})

# Setup a DataFrame with corresponding hover values
tooltips_df = pd.DataFrame({
    'temp': ['i am message 1', 'i am foo', 'i am lala'],
    'var2': ' another random message',
    'col3': 'more random messages'
})

# Assign tooltips
foo.style.set_tooltips(tooltips_df)

t = st.empty()
t.dataframe( foo.style.set_tooltips(tooltips_df) )

then I get error: β€˜int’ object has no attribute β€˜strip’
from:

File "../venv/lib/python3.8/site-packages/streamlit/elements/arrow.py", line 314, in _pandas_style_to_css
    declaration = css_property.strip() + ": " + css_value.strip()
1 Like

Perhaps you could employ Plotly (still within Streamlit) for this? Please, refer to the corresponding page in Plotly’s documentation: DataTable Tooltips | Dash for Python Documentation | Plotly.

Hey there @endrem, did you solf your problem? I’m interested.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.