Dataframe example

a demo of the Dataframe plugin for TiddlyWiki5

HelloThere

This is a demo of TiddlyWiki5 incorporating a plugin by Hylke W. van Dijk to display (pandas) dataframe

You might want to check out:

Source code is available at: https://bitbucket.org/hwvandijk/tw-dataframe/

DataframeExample

Introduction

Pandas Dataframes are flexible and rich data objects to store, order, and re-order your data. This plugin allows you to display dataframes as a whole, in part, and access per entry.

Examples

A quick inspection of a dataframe uses a template: {{data/df/foobar||tags/dataframe.template}}

shape: ( 8, 4 )
name: id
ranges: ( 0,7 – 0,3 )
dataframe: data/df/foobar.values

id Class Super Inherited Instantiations
0 Bar Foo Fubar 10,000
1 Child Parent Sibling 8,972
2 Branch Tree Leaf 4,242
3 Mansion House Cottage 3,293
4 Beer Whiskey Larger 2,321
5 Coffee Tea Latte 1,275
6        
7 Total     30,103

Accessing entries of data frame

By (index, column) where index and columns are both integers starting from (0,0)

e.g., <<df-iloc 0,0>>

Bar

By (index, column) where index and columns refer to the index (row) and columns names

e.g., <<df-loc 0,Class>>

Bar

By excel/calc naming convention (A2).

Obviously this only works if the data has been prepared.

e.g. <<df-xloc A2 dataframe:"data/excel/foobar">>

Bar

The excel version of data/df/foobar can be inspected by {{data/excel/foobar||tags/dataframe.template}} and yields

shape: ( 9, 4 )
name: id
ranges: ( 0,8 – 0,3 )
dataframe: data/excel/foobar.values

id A B C D
1 Class Super Inherited Instantiations
2 Bar Foo Fubar 10,000
3 Child Parent Sibling 8,972
4 Branch Tree Leaf 4,242
5 Mansion House Cottage 3,293
6 Beer Whiskey Larger 2,321
7 Coffee Tea Latte 1,275
8        
9 Total     30,103

Presentation as a table

Let dataframe be a field of this tiddler, i.e. dataframe: data/df/foobar. The <<df-xyz>> macros take by default the dataframe parameter from the dataframe field of the current tiddler.

Hence <<df>> equals <<df dataframe:{{!!dataframe}}>>:

id Class Super Inherited Instantiations
0 Bar Foo Fubar 10,000
1 Child Parent Sibling 8,972
2 Branch Tree Leaf 4,242
3 Mansion House Cottage 3,293
4 Beer Whiskey Larger 2,321
5 Coffee Tea Latte 1,275
6        
7 Total     30,103

Specifier(s) for index and columns

The df macro takes two range specifications. One for index and one for columns, in that order. Thus <<df index:range-specification columns:range-specification>>

Range specifiers take the form of a comma separated sequence of identifiers, where an identifier is

  • a single number, i, that refers to a single index or column (starting from 0) like df-iloc above, or
  • a tuple x-y, where x refers to the starting index or column and y to the end of the range, i.e., the range filter operator.

Examples of valid specifiers are 0,1,5-8, 2,3-7,2, and 8-5,1,0 which expand to respectively [0 1 5 6 7 8], [2 3 4 5 6 7 2], and [8 7 6 5 1 0].

As an example <<df index:0,2,4-5 columns:0-3>>

id Class Super Inherited Instantiations
0 Bar Foo Fubar 10,000
2 Branch Tree Leaf 4,242
4 Beer Whiskey Larger 2,321
5 Coffee Tea Latte 1,275

Controlling the presentation

<<df>> takes 5 parameters: <<df [index, columns, dataframe, headers, tags] >>

index, columns and dataframe have been introduced above,

headers and tags let you specify the html code of a presentation, see the man pages man/df/dataframe for details.

Using a style

<<df-dataframe> is a convenience version of <<df>> that uses a CSS style sheet build on .dataframe html class.

<<df-dataframe>> takes a single style parameter, which is basically a list of classes that control the presentation.

Two examples:

<<df-dataframe>>

id Class Super Inherited Instantiations
0 Bar Foo Fubar 10,000
1 Child Parent Sibling 8,972
2 Branch Tree Leaf 4,242
3 Mansion House Cottage 3,293
4 Beer Whiskey Larger 2,321
5 Coffee Tea Latte 1,275
6        
7 Total     30,103

<<df-dataframe style:colored.striped.align-right>>

id Class Super Inherited Instantiations
0 Bar Foo Fubar 10,000
1 Child Parent Sibling 8,972
2 Branch Tree Leaf 4,242
3 Mansion House Cottage 3,293
4 Beer Whiskey Larger 2,321
5 Coffee Tea Latte 1,275
6        
7 Total     30,103

You can interactively experiment with the class options in man page man/df/df-dataframe-style.

Man pages

See:

Developers Subtleties

During the development of the dataframe plugin I encountered, and overcame, some interesting subtleties.

Resolved

With the help of the tiddlywiki group, in particular Mat and Saq, the subtleties have been explained and resolved. You find the remarks in the respective subtlety below.

Subtleties

For those interested you can find them here: