1

Is there a way to export a pandas dataframe into an HTML file and incorporate some additional code that makes the output sortable by column?

I have been using Dash DataTable to give the user the option to sort the results, but I was wondering if there is another way in which a server running is not needed and the user can just load the HTML page and sort the results.

So far I have been able to have semi interactive plots based on this SO post, but I would like to add also sortable tables in the HTML and after searching online I am not clear what is the best way to do it (still a newbie with HTML)

datapug
  • 1,991
  • 1
  • 12
  • 30

1 Answers1

0

For sorting you have to use JavaScript and for the exporting part use method pandas.DataFrame.to_html().

Nick ODell
  • 9,210
  • 2
  • 26
  • 54
The Mask
  • 302
  • 2
  • 14
  • Do you have any reference link on what is the proper way to incorporate JavaScript for the sorting? – datapug Dec 16 '20 at 18:46
  • pandas.Dataframe.to_html() will convert the Dataframe into element.After that you can try this https://stackoverflow.com/questions/14267781/sorting-html-table-with-javascript SO answer for sorting purpose.
    – The Mask Dec 16 '20 at 19:00
  • If this worked out for you then please mark it as accepted so that others can take advantage of it. – The Mask Dec 17 '20 at 07:20
  • It didn't work yet: I am new to JS and when I tried the code in the post mentioned (and wrapped the script into `` and `window.onload=function()` ) and it still not working. I'll accept the answer when I figure out why is not working or when a working snippet is provided in this post. – datapug Dec 17 '20 at 15:50