mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
768 stars 56 forks source link

Pandas background gradient (heatmap) #194

Closed matinnuhamunada closed 1 year ago

matinnuhamunada commented 1 year ago

Hi, is it possible to convert the heatmap view from pandas in itables?

import pandas as pd
import seaborn as sns

cm = sns.light_palette("green", as_cmap=True)

# Create a sample DataFrame
data = {
    'A': [1, 3, 5, 7],
    'B': [2, 4, 6, 8],
    'C': [3, 6, 9, 12]
}

df = pd.DataFrame(data)

# Apply heatmap styling
styled_df = df.style.background_gradient(cmap=cm)
styled_df
mwouts commented 1 year ago

Hi @matinnuhamunada , nice question, thanks. At some point I would like to provide support for Pandas' style, but at the moment there is nothing like this.

If you feel like coding this in JavaScript this is the only current option. You could start from this example: https://mwouts.github.io/itables/advanced_parameters.html#advanced-cell-formatting-with-js-callbacks

Please let this issue open, I might use to to report on progress re the support for style.

Kind regards

mwouts commented 1 year ago

Hi @matinnuhamunada , actually I think I can support this too. I have prepared a PR #196 .

Would you mind giving a try at the development version? You can get it with

pip install git+https://github.com/mwouts/itables.git@support_style

Let me know how it goes for you.