I'm trying to highlight largest value in each column of my DataFrame. It's working well in my laptop but not in my pydroid3 mobile app...
data = {'Column1': [10, 15, 8],
'Column2': [20, 5, 12],
'Column3': [7, 18, 9]}
df = pd.DataFrame(data)
#print(df)
I tried as ...
df_styled = df.style.highlight_max(color='lightgreen')
print(df_styled)
Here I'm getting following as output...
<pandas.io.formats.style.Styler object at 0x76f9790520>
What does it mean and how can I get df.style on my Android app ??
The output of Styler objects is visible in a Notebook (for example in Jupyter Lab or Google Colaboratory) because Notebooks have special handling for Pandas objects. If you run the code in regular Python (i.e., directly in the terminal) on a laptop or desktop computer then you get just the name of the object and no graphical output. Pydroid 3 works like a terminal, and displays only the textual output.
If you do want to show the table with colors, then there may be some options. The Styler class has functions to export the object in four different formats: plain text, html, LaTeX, and xlsx.
The plain text export removes the colors, so this is not suitable. The LaTeX export might be an option, but it is complicated (it would require sending the LaTeX code somewhere to be compiled, retrieving and possibly converting the result and showing it in the app) and the basic export function does not handle the colors well (i.e., it does not produce valid LaTeX by default, this may be customizable). The Excel export preserves the colors, but it is probably not very convenient to display the result in an app - unless this is standalone output that you want to offer to the user for download, then it can be a nice option.
The remaining option is html output. Depending on how the app is designed it may be feasible to either show the rendered html directly or in a (possibly headless) browser window, or to convert the html in the background to an image and show that image.
Code:
Output:
Another alternative is to render the table through Matplotlib. Pydroid supports graphical output from this library out of the box. Matplotlib has a function to plot a dataframe as a table, so this is rather easy. Unfortunately Matplotlib does not support Styler objects, so you need to do the styling yourself. Code:
The following output is from a Notebook for comparison, but the Matplotlib part works on Pydroid 3 as well.