How to install gviz_data_table
- Download and install ActivePython
- Open Command Prompt
pypm install gviz-data-table
Gviz Data Table is a simple Python library for converting Python data types to the Google Visualization Data Table JSON format. https://developers.google.com/chart/interactive/docs/reference
Gviz Data Table is designed primarily for use with data sources such as databases. Usage is supposed to be minimal: you provide a schema, that is a list of columns, and the rows of data. A column must have a name and Python data type. It can also have a label which will be used for display, otherwise the name will be used.
Each row is a sequence of cells. Although columns are explicit row names are always the first cell in a row. Like columns, cells can also have labels. Gviz Data Table will validate each cell to make sure that data conforms to type specified in the schema and will map Python types to their JSON equivalent but it does not coerce any data, i.e. if a column has type int and a cell's data is a string containing numerical characters only this will still raise an exception.
Gviz Data Table is composed of: one container class "Table"; two data classes, Cell and Column and one JSON encoder. Application code should probably only ever need to use Table and the encoder.
Tables can be initialised with a schema or these can be added imperatively. Once one row has been added to a table no more columns can be added. Once all the rows have been added. The table can be converted into JSON using the encoder.
Let's say we have data representing the names and salaries of people
This could be coded in Gviz Data Table like this:
This can be encoded into JSON using the encoder:
It can also be directly encoded
Complete documentation including the API at http://gviz-data-table.readthedocs.org/en/latest/
- Python 3 compatibile
- Changed convenience import: encode replaces encoder
- Added convenience methods to Table to allow direct encoding as JSON and a Google data source.
- Changed signature of add_column when I found I used it wrongly myself in
- Initial release