Skip to content

Commit c8b680a

Browse files
authored
Merge pull request #14 from hawkfish/voila
Add examples for Fold and Unfold.
2 parents a5e68f1 + 5c4c6ad commit c8b680a

File tree

2 files changed

+99
-5
lines changed

2 files changed

+99
-5
lines changed

docs/transforms/reshapes/fold.rst

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,53 @@ Usage
4343

4444
.. code-block:: python
4545
46-
Fold(p, ('Sales 1992', 'Sales 1993', 'Sales 1994',), ('Year', 'Sales',))
47-
Fold(p, ('Sales 1992', 'Sales 1993', 'Sales 1994', 'Profit 1992', 'Profit 1993', 'Profit 1994',), ('Year', 'Sales', 'Profit',))
46+
Fold(p, ('Sales 1992', 'Sales 1993', 'Sales 1994',),
47+
('Year', 'Sales',), ('1992', '1993', '1994',))
48+
Fold(p, ('Sales 1992', 'Sales 1993', 'Sales 1994', 'Profit 1992', 'Profit 1993', 'Profit 1994',),
49+
('Year', 'Sales', 'Profit',), ('1992', '1993', '1994',))
50+
51+
Examples
52+
^^^^^^^^
53+
54+
Single Fold
55+
-----------
56+
57+
.. csv-table:: Input
58+
:header: "Key", "Sales 1992", "Sales 1993", "Sales 1994"
59+
:align: left
60+
61+
0, "S-0-1992", "S-0-1993", "S-0-1994"
62+
1, "S-1-1992", "S-1-1993", "S-1-1994"
63+
64+
.. csv-table:: Output
65+
:header: "Key", "Year", "Sales"
66+
:align: left
67+
68+
0, 1992, "S-0-1992"
69+
0, 1993, "S-0-1993"
70+
0, 1994, "S-0-1994"
71+
1, 1992, "S-1-1992"
72+
1, 1993, "S-1-1993"
73+
1, 1994, "S-1-1994"
74+
75+
Multiple Folds
76+
--------------
77+
78+
.. csv-table:: Input
79+
:header: "Key", "Sales 1992", "Sales 1993", "Sales 1994", "Profit 1992", "Profit 1993", "Profit 1994"
80+
:align: left
81+
:widths: 1, 8, 8, 8, 8, 8, 8
82+
83+
0, "S-0-1992", "S-0-1993", "S-0-1994", "P-0-1992", "P-0-1993", "P-0-1994"
84+
1, "S-1-1992", "S-1-1993", "S-1-1994", "P-1-1992", "P-1-1993", "P-1-1994"
85+
86+
.. csv-table:: Output
87+
:header: "Key", "Year", "Sales", "Profit"
88+
:align: left
89+
90+
0, 1992, "S-0-1992", "P-0-1992"
91+
0, 1993, "S-0-1993", "P-0-1993"
92+
0, 1994, "S-0-1994", "P-0-1994"
93+
1, 1992, "S-1-1992", "P-1-1992"
94+
1, 1993, "S-1-1993", "P-1-1993"
95+
1, 1994, "S-1-1994", "P-1-1994"

docs/transforms/reshapes/unfold.rst

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Unfold: Rotate one field to many
66
.. py:class:: Unfold(source, inputs, outputs)
77
88
The ``Unfold`` transform unfolds (pivots) a set of fields.
9-
Simple unfolding consists of rotating a single input fields into multiple output fields.
10-
This can be generalised to multiple input fields where the output fields
11-
are broken up into equal-sized groups, each of which is generated from one of the input fields.
9+
Simple unfolding consists of rotating a single input field into multiple output fields.
10+
This can be generalised to multiple input fields where the output fields are broken up into equal-sized groups,
11+
and each group is generated from one of the input fields.
1212
``Unfold`` is the inverse of :py:class:`Fold`.
1313

1414
.. py:attribute:: source
@@ -45,3 +45,49 @@ Usage
4545
4646
Unfold(p, ('Year', 'Sales',), ('Sales 1992', 'Sales 1993', 'Sales 1994',))
4747
Unfold(p, ('Year', 'Sales', 'Profit',), ('Sales 1992', 'Sales 1993', 'Sales 1994', 'Profit 1992', 'Profit 1993', 'Profit 1994',))
48+
49+
Examples
50+
^^^^^^^^
51+
52+
Single Fold
53+
-----------
54+
55+
.. csv-table:: Input
56+
:header: "Key", "Year", "Sales"
57+
:align: left
58+
59+
0, 1992, "S-0-1992"
60+
0, 1993, "S-0-1993"
61+
0, 1994, "S-0-1994"
62+
1, 1992, "S-1-1992"
63+
1, 1993, "S-1-1993"
64+
1, 1994, "S-1-1994"
65+
66+
.. csv-table:: Output
67+
:header: "Key", "Sales 1992", "Sales 1993", "Sales 1994"
68+
:align: left
69+
70+
0, "S-0-1992", "S-0-1993", "S-0-1994"
71+
1, "S-1-1992", "S-1-1993", "S-1-1994"
72+
73+
Multiple Folds
74+
--------------
75+
76+
.. csv-table:: Input
77+
:header: "Key", "Year", "Sales", "Profit"
78+
:align: left
79+
80+
0, 1992, "S-0-1992", "P-0-1992"
81+
0, 1993, "S-0-1993", "P-0-1993"
82+
0, 1994, "S-0-1994", "P-0-1994"
83+
1, 1992, "S-1-1992", "P-1-1992"
84+
1, 1993, "S-1-1993", "P-1-1993"
85+
1, 1994, "S-1-1994", "P-1-1994"
86+
87+
.. csv-table:: Output
88+
:header: "Key", "Sales 1992", "Sales 1993", "Sales 1994", "Profit 1992", "Profit 1993", "Profit 1994"
89+
:align: left
90+
:widths: 1, 8, 8, 8, 8, 8, 8
91+
92+
0, "S-0-1992", "S-0-1993", "S-0-1994", "P-0-1992", "P-0-1993", "P-0-1994"
93+
1, "S-1-1992", "S-1-1993", "S-1-1994", "P-1-1992", "P-1-1993", "P-1-1994"

0 commit comments

Comments
 (0)