Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a pandas data frame with Bokeh

Tags:

python

bokeh

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.

like image 925
helloB Avatar asked May 26 '16 20:05

helloB


People also ask

Does Bokeh work with pandas?

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.

What is ColumnDatasource Bokeh?

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.


1 Answers

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"),
    ]
like image 107
Nils Avatar answered Sep 17 '22 16:09

Nils