Displaying a Pandas DataFrame in zero-true
Displaying a DataFrame
Pandas is one of the most popular python libraries for data analysis so sooner or later you are bound to use one of their “DataFrames” within your zero-true notebook. Once you have a dataframe that you’d like to display in zero-true, actually getting it to render on the frontend is simple. Take a look at the code snippet below where we load a dataframe from wikipedia and then display it with zero-true (readhtml will require you to have the library lxml installed in the same environment):
Run the cell in your notebook, and watch the dataframe appear below! Like all other zero-true components, dataframes require an ID as well as a pandas df passed as arguments to render. Since dataframes are static components in zero-true there are no values for you to access that users interact with.
Filtering a DataFrame in Zero-True
Let’s take the code above and make it a little bit more exciting by interactively filtering the dataframe with a slider in zero-true:
This will display the “top n books” where n is the value that the user selects using the slider. Dataframes can be useful when you have a range of text and numbers and more standard visualizations like plots fail to capture the entire story.