flatbread 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flatbread-0.1.0 → flatbread-0.1.1}/PKG-INFO +9 -11
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/tooling.py +36 -8
- {flatbread-0.1.0 → flatbread-0.1.1}/pyproject.toml +1 -1
- {flatbread-0.1.0 → flatbread-0.1.1}/readme.md +8 -10
- {flatbread-0.1.0 → flatbread-0.1.1}/.gitignore +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/environment.yml +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/__init__.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/accessors/dataframe.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/accessors/index.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/accessors/series.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/agg/aggregation.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/agg/totals.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/chaining.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/config/config.defaults.json +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/config.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/percentages.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/config.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/constants.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/display.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/tablespec.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/template.jinja.html +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/render/template.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/flatbread/testing/dataframe.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/license.md +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/__init__.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/aggregate/__init__.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/aggregate/test_percentages.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/aggregate/test_totals.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/test_axes.py +0 -0
- {flatbread-0.1.0 → flatbread-0.1.1}/tests/test_levels.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flatbread
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Pandas extension for aggregation and tabular display
|
|
5
5
|
Project-URL: Homepage, https://github.com/lcvriend/flatbread
|
|
6
6
|
Author-email: "L.C. Vriend" <vanboefer@gmail.com>
|
|
@@ -695,20 +695,18 @@ Requires-Dist: jinja2
|
|
|
695
695
|
Requires-Dist: pandas>=2.0.0
|
|
696
696
|
Description-Content-Type: text/markdown
|
|
697
697
|
|
|
698
|
-
Here's a concise README for flatbread:
|
|
699
|
-
|
|
700
|
-
```markdown
|
|
701
698
|
# Flatbread
|
|
702
699
|
|
|
703
|
-
Flatbread is a Python library that extends pandas with tabulation features
|
|
700
|
+
Flatbread is a Python library that extends pandas with tabulation features. It makes it easy to create and display summary tables with totals, subtotals, percentages, and aggregations.
|
|
704
701
|
|
|
705
702
|
Flatbread can be accessed in `DataFrames` and `Series` using the `pita` accessor.
|
|
706
703
|
|
|
704
|
+
It uses the [wc-simple-table](https://github.com/lcvriend/wc-simple-table) dataviewer web component to display tables in a notebook: [check out some examples](https://lcvriend.github.io/wc-simple-table/).
|
|
705
|
+
|
|
707
706
|
## Key Features
|
|
708
707
|
|
|
709
708
|
- Add row and column totals/subtotals to DataFrames and Series
|
|
710
709
|
- Calculate and format percentages with proper rounding
|
|
711
|
-
- Chain operations
|
|
712
710
|
- Preserve data types and index structures
|
|
713
711
|
- Table display in Jupyter notebooks
|
|
714
712
|
|
|
@@ -720,12 +718,12 @@ import flatbread
|
|
|
720
718
|
|
|
721
719
|
df = pd.DataFrame(...)
|
|
722
720
|
|
|
723
|
-
# Add totals and percentages
|
|
721
|
+
# Add totals and percentages
|
|
724
722
|
result = (
|
|
725
|
-
df
|
|
726
|
-
.add_totals() # Add grand totals
|
|
727
|
-
.add_subtotals(level=0) # Add subtotals by first index level
|
|
728
|
-
.add_percentages() # Add percentage columns
|
|
723
|
+
df
|
|
724
|
+
.pita.add_totals() # Add grand totals
|
|
725
|
+
.pita.add_subtotals(level=0) # Add subtotals by first index level
|
|
726
|
+
.pita.add_percentages() # Add percentage columns
|
|
729
727
|
)
|
|
730
728
|
|
|
731
729
|
# Display with interactive viewer
|
|
@@ -86,7 +86,7 @@ def sort_totals(
|
|
|
86
86
|
@singledispatch
|
|
87
87
|
def add_level(
|
|
88
88
|
data,
|
|
89
|
-
|
|
89
|
+
values: Any|list[Any],
|
|
90
90
|
level: int = 0,
|
|
91
91
|
level_name: Any = None,
|
|
92
92
|
axis: Axis = 0,
|
|
@@ -97,7 +97,7 @@ def add_level(
|
|
|
97
97
|
@add_level.register
|
|
98
98
|
def _(
|
|
99
99
|
data: pd.DataFrame,
|
|
100
|
-
value: Any,
|
|
100
|
+
value: Any|list[Any],
|
|
101
101
|
level: int = 0,
|
|
102
102
|
level_name: Any = None,
|
|
103
103
|
axis: Axis = 0,
|
|
@@ -109,8 +109,8 @@ def _(
|
|
|
109
109
|
----------
|
|
110
110
|
data (pd.DataFrame):
|
|
111
111
|
Input DataFrame.
|
|
112
|
-
value
|
|
113
|
-
|
|
112
|
+
value Any|list[Any]
|
|
113
|
+
Either a single value to fill the entire level with, or a list of values with length matching the axis size. Values will be mapped in order.
|
|
114
114
|
level (int, optional):
|
|
115
115
|
Position to insert the new level. Defaults to 0 (start).
|
|
116
116
|
level_name (Any, optional):
|
|
@@ -126,11 +126,25 @@ def _(
|
|
|
126
126
|
data = data.copy()
|
|
127
127
|
target = data.index if axis in [0, 'index'] else data.columns
|
|
128
128
|
|
|
129
|
+
if isinstance(value, list):
|
|
130
|
+
if len(value) != len(target):
|
|
131
|
+
raise ValueError(
|
|
132
|
+
f"Length of values list ({len(value)}) must match "
|
|
133
|
+
f"length of {'index' if axis in [0, 'index'] else 'columns'} ({len(target)})"
|
|
134
|
+
)
|
|
135
|
+
|
|
129
136
|
if not isinstance(target, pd.MultiIndex):
|
|
130
137
|
original_name = target.name
|
|
131
138
|
target = pd.MultiIndex.from_arrays([target], names=[original_name])
|
|
132
139
|
|
|
133
|
-
new_keys = [
|
|
140
|
+
new_keys = [
|
|
141
|
+
add_value_to_key(
|
|
142
|
+
key,
|
|
143
|
+
value[i] if isinstance(value, list) else value,
|
|
144
|
+
level
|
|
145
|
+
)
|
|
146
|
+
for i, key in enumerate(target)
|
|
147
|
+
]
|
|
134
148
|
new_names = add_value_to_key(target.names, level_name, level)
|
|
135
149
|
new_index = pd.MultiIndex.from_tuples(new_keys, names=new_names)
|
|
136
150
|
|
|
@@ -156,8 +170,8 @@ def _(
|
|
|
156
170
|
----------
|
|
157
171
|
data (pd.Series):
|
|
158
172
|
Input Series.
|
|
159
|
-
value
|
|
160
|
-
|
|
173
|
+
value Any|list[Any]
|
|
174
|
+
Either a single value to fill the entire level with, or a list of values with length matching the axis size. Values will be mapped in order.
|
|
161
175
|
level (int, optional):
|
|
162
176
|
Position to insert the new level. Defaults to 0 (start).
|
|
163
177
|
level_name (Any, optional):
|
|
@@ -173,11 +187,25 @@ def _(
|
|
|
173
187
|
data = data.copy()
|
|
174
188
|
target = data.index
|
|
175
189
|
|
|
190
|
+
if isinstance(value, list):
|
|
191
|
+
if len(value) != len(target):
|
|
192
|
+
raise ValueError(
|
|
193
|
+
f"Length of values list ({len(value)}) must match "
|
|
194
|
+
f"length of index ({len(target)})"
|
|
195
|
+
)
|
|
196
|
+
|
|
176
197
|
if not isinstance(target, pd.MultiIndex):
|
|
177
198
|
original_name = target.name
|
|
178
199
|
target = pd.MultiIndex.from_arrays([target], names=[original_name])
|
|
179
200
|
|
|
180
|
-
new_keys = [
|
|
201
|
+
new_keys = [
|
|
202
|
+
add_value_to_key(
|
|
203
|
+
key,
|
|
204
|
+
value[i] if isinstance(value, list) else value,
|
|
205
|
+
level
|
|
206
|
+
)
|
|
207
|
+
for i, key in enumerate(target)
|
|
208
|
+
]
|
|
181
209
|
new_names = add_value_to_key(target.names, level_name, level)
|
|
182
210
|
new_index = pd.MultiIndex.from_tuples(new_keys, names=new_names)
|
|
183
211
|
data.index = new_index
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
Here's a concise README for flatbread:
|
|
2
|
-
|
|
3
|
-
```markdown
|
|
4
1
|
# Flatbread
|
|
5
2
|
|
|
6
|
-
Flatbread is a Python library that extends pandas with tabulation features
|
|
3
|
+
Flatbread is a Python library that extends pandas with tabulation features. It makes it easy to create and display summary tables with totals, subtotals, percentages, and aggregations.
|
|
7
4
|
|
|
8
5
|
Flatbread can be accessed in `DataFrames` and `Series` using the `pita` accessor.
|
|
9
6
|
|
|
7
|
+
It uses the [wc-simple-table](https://github.com/lcvriend/wc-simple-table) dataviewer web component to display tables in a notebook: [check out some examples](https://lcvriend.github.io/wc-simple-table/).
|
|
8
|
+
|
|
10
9
|
## Key Features
|
|
11
10
|
|
|
12
11
|
- Add row and column totals/subtotals to DataFrames and Series
|
|
13
12
|
- Calculate and format percentages with proper rounding
|
|
14
|
-
- Chain operations
|
|
15
13
|
- Preserve data types and index structures
|
|
16
14
|
- Table display in Jupyter notebooks
|
|
17
15
|
|
|
@@ -23,12 +21,12 @@ import flatbread
|
|
|
23
21
|
|
|
24
22
|
df = pd.DataFrame(...)
|
|
25
23
|
|
|
26
|
-
# Add totals and percentages
|
|
24
|
+
# Add totals and percentages
|
|
27
25
|
result = (
|
|
28
|
-
df
|
|
29
|
-
.add_totals() # Add grand totals
|
|
30
|
-
.add_subtotals(level=0) # Add subtotals by first index level
|
|
31
|
-
.add_percentages() # Add percentage columns
|
|
26
|
+
df
|
|
27
|
+
.pita.add_totals() # Add grand totals
|
|
28
|
+
.pita.add_subtotals(level=0) # Add subtotals by first index level
|
|
29
|
+
.pita.add_percentages() # Add percentage columns
|
|
32
30
|
)
|
|
33
31
|
|
|
34
32
|
# Display with interactive viewer
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|