Created
September 9, 2024 23:02
-
-
Save chewbranca/c7a834d214e115a9aceb06c432a5d63a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "ddd0ffed-c9f6-42e6-8384-49b567642240", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"G1 groupby(\"X\") GROUPS {'A': [0, 2], 'B': [1, 3]}\n", | |
"\n", | |
"\t[$K] -- [$V] || [A] -- [<class 'pandas.core.frame.DataFrame'>]\n", | |
"\n", | |
"\t[$K] -- [$V] || [B] -- [<class 'pandas.core.frame.DataFrame'>]\n", | |
"\n", | |
"G2 groupby([\"X\"]) GROUPS {'A': [0, 2], 'B': [1, 3]}\n", | |
"\n", | |
"\t[$K] -- [$V] || [('A',)] -- [<class 'pandas.core.frame.DataFrame'>]\n", | |
"\n", | |
"\t[$K] -- [$V] || [('B',)] -- [<class 'pandas.core.frame.DataFrame'>]\n" | |
] | |
} | |
], | |
"source": [ | |
"import pandas as pd\n", | |
"\n", | |
"df1 = pd.DataFrame({\"X\": [\"A\", \"B\", \"A\", \"B\"], \"Y\": [1, 4, 3, 2]})\n", | |
"\n", | |
"g1 = df1.groupby(\"X\")\n", | |
"print(\"G1 groupby(\\\"X\\\") GROUPS\", g1.groups)\n", | |
"for k, v in g1:\n", | |
" print(\"\\n\\t[$K] -- [$V] || [{0}] -- [{1}]\".format(k, type(v)))\n", | |
" \n", | |
"g2 = df1.groupby([\"X\"])\n", | |
"print(\"\\nG2 groupby([\\\"X\\\"]) GROUPS\", g2.groups)\n", | |
"for k, v in g2:\n", | |
" print(\"\\n\\t[$K] -- [$V] || [{0}] -- [{1}]\".format(k, type(v)))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.12.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment