Is there a nice way to display data frames with Bokeh? I have a bunch of table-based text I'd like to display and dynamically update along with some graphs, but I haven't found a good way to do this yet.
Pandas-Bokeh provides a Bokeh plotting backend for Pandas, GeoPandas and Pyspark DataFrames, similar to the already existing Visualization feature of Pandas. Importing the library adds a complementary plotting method plot_bokeh() on DataFrames and Series.
Advertisements. Most of the plotting methods in Bokeh API are able to receive data source parameters through ColumnDatasource object. It makes sharing data between plots and 'DataTables'. A ColumnDatasource can be considered as a mapping between column name and list of data.
You should take a look into bokeh.models.widgets.DataTable
http://docs.bokeh.org/en/latest/docs/user_guide/interaction.html#data-table
Example:
from datetime import date
from random import randint
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.io import output_file, show, vform
output_file("data_table.html")
data = dict(
dates=[date(2014, 3, i+1) for i in range(10)],
downloads=[randint(0, 100) for i in range(10)],
)
source = ColumnDataSource(data)
columns = [
TableColumn(field="dates", title="Date", formatter=DateFormatter()),
TableColumn(field="downloads", title="Downloads"),
]
data_table = DataTable(source=source, columns=columns, width=400, height=280)
show(vform(data_table))
You could exchange data with your own DataFrame like:
data = dict(df[['first', 'second']])
If the column names differ please change columns variable to:
columns = [
TableColumn(field="first", title="First"),
TableColumn(field="second", title="Second"),
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With