Skip to content

Commit 4f7cfe4

Browse files
committed
try except for failing case & typo fix
1 parent f3f0c08 commit 4f7cfe4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

docs/tutorials/groupby_doc.ipynb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"# GroupBy for NestedPandas\n",
99
"\n",
1010
"This notebook explores how Pandas' built-in `groupby` interacts with `NestedPandas` structures.\n",
11-
"<!-- highlight what works, what doesn’t, and why — with clear examples and explanations. -->\n",
1211
"\n",
1312
"Because Nested-Pandas extends the Pandas library, native ``pandas.DataFrame.groupby`` works with nested-pandas out of the box in some ways. "
1413
]
@@ -59,7 +58,7 @@
5958
"\n",
6059
"- Some built-in methods like `count` work but not as expected (view nested column as a single object).\n",
6160
"- Others (`min`, `max`, `mean`) fail on nested columns.\n",
62-
"- Interestingly, `describe` will work as expcted with the automatic flattened nested column."
61+
"- Interestingly, `describe` will work as expected with the automatic flattened nested column."
6362
]
6463
},
6564
{
@@ -69,7 +68,7 @@
6968
"metadata": {},
7069
"outputs": [],
7170
"source": [
72-
"# count is viewing nested columns as signle objects\n",
71+
"# count is viewing nested columns as single objects\n",
7372
"nf.groupby(\"c\").count()"
7473
]
7574
},
@@ -81,7 +80,11 @@
8180
"outputs": [],
8281
"source": [
8382
"# min/max/mean fail on nested columns\n",
84-
"nf.groupby(\"c\").min() # will produce error"
83+
"try:\n",
84+
" grouped_min = nf.groupby(\"c\").min()\n",
85+
" print(grouped_min)\n",
86+
"except TypeError as e:\n",
87+
" print(f\"Cannot compute min on nested columns: {e}\")"
8588
]
8689
},
8790
{
@@ -101,7 +104,7 @@
101104
"metadata": {},
102105
"source": [
103106
"## Type Preservation\n",
104-
"Within each group, the object remains accessible as ``NestedFrame`` object and the nested columns remain ``NestedSeries``.\n",
107+
"Within each group, the object remains accessible as a ``NestedFrame`` object and the nested columns remain ``NestedSeries``.\n",
105108
"\n",
106109
"We can check this by applying a custom function on our 2-group `groupby` object:"
107110
]
@@ -208,7 +211,7 @@
208211
"\n",
209212
"`.apply()` for nested operations is supported natively. It generally works if the function flattens or use index slicing to ensure matching type for operations. \n",
210213
"\n",
211-
"Some potential exmaples:"
214+
"Some potential examples:"
212215
]
213216
},
214217
{
@@ -255,13 +258,15 @@
255258
"- Use **slice-based indexing** (.iloc[0:1]) to preserve nested types.\n",
256259
"- Use **.nest.to_flat()** to flatten a nested column when needed for numerical or aggregating operations.\n",
257260
"\n",
258-
"- Nested structures are designed to reduce the need for expensive groupby operations by allowing data to stay organized hierarchically. However, when grouping is necessary, pandas’ groupby still works with nested-pandas and maintains type consistency."
261+
"- Nested structures are designed to reduce the need for expensive groupby operations by allowing data to stay organized hierarchically. However, when grouping is necessary, pandas’ groupby still works with nested-pandas and maintains type consistency.\n",
262+
"\n",
263+
"- Some use cases may behave unexpectedly because of the nested structures. We encourage users to open issues if you run into unexpected behavior or edge cases.\n"
259264
]
260265
}
261266
],
262267
"metadata": {
263268
"kernelspec": {
264-
"display_name": "Python 3 (ipykernel)",
269+
"display_name": ".venv",
265270
"language": "python",
266271
"name": "python3"
267272
},

0 commit comments

Comments
 (0)