Last active
December 11, 2023 03:23
-
-
Save pybokeh/3c4ddaeec4c98d3f8454a9a8ed0b0b5d to your computer and use it in GitHub Desktop.
This file contains 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": "adb05f7f-b0fc-420d-a7d0-0045cbfe2be8", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import ibis\n", | |
"import ibis.selectors as s\n", | |
"import io\n", | |
"import pandas as pd\n", | |
"from ibis import _\n", | |
"ibis.options.interactive = True\n", | |
"pd.options.display.max_rows=1000\n", | |
"\n", | |
"# create a DuckDB client\n", | |
"client = ibis.duckdb.connect()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "228abfe9-bd27-4b40-979d-fd039ef0ebac", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data = \"\"\"\n", | |
"yr_month,part1,part2\n", | |
"2019-03,nan,1\n", | |
"2019-04,1,nan\n", | |
"2019-05,nan,nan\n", | |
"2019-06,2,nan\n", | |
"2019-07,nan,2\n", | |
"2019-08,nan,nan\n", | |
"2019-09,4,nan\n", | |
"2019-10,8,3\n", | |
"2019-11,9,nan\n", | |
"2019-12,10,5\n", | |
"2020-01,13,nan\n", | |
"2020-02,14,14\n", | |
"2020-03,15,15\n", | |
"2020-04,nan,17\n", | |
"2020-05,16,18\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "1550f6d8-ba96-4b09-b21e-88293f726e6a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pdf = pd.read_csv(io.StringIO(data))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "f44eb6e7-cacf-4c8a-9398-b4fb7f9c278a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>yr_month</th>\n", | |
" <th>part1</th>\n", | |
" <th>part2</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>2019-03</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2019-04</td>\n", | |
" <td>1.0</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>2019-05</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>2019-06</td>\n", | |
" <td>2.0</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>2019-07</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>2019-08</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>2019-09</td>\n", | |
" <td>4.0</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>2019-10</td>\n", | |
" <td>8.0</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>2019-11</td>\n", | |
" <td>9.0</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>2019-12</td>\n", | |
" <td>10.0</td>\n", | |
" <td>5.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>2020-01</td>\n", | |
" <td>13.0</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>2020-02</td>\n", | |
" <td>14.0</td>\n", | |
" <td>14.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>2020-03</td>\n", | |
" <td>15.0</td>\n", | |
" <td>15.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>2020-04</td>\n", | |
" <td>NaN</td>\n", | |
" <td>17.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>2020-05</td>\n", | |
" <td>16.0</td>\n", | |
" <td>18.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" yr_month part1 part2\n", | |
"0 2019-03 NaN 1.0\n", | |
"1 2019-04 1.0 NaN\n", | |
"2 2019-05 NaN NaN\n", | |
"3 2019-06 2.0 NaN\n", | |
"4 2019-07 NaN 2.0\n", | |
"5 2019-08 NaN NaN\n", | |
"6 2019-09 4.0 NaN\n", | |
"7 2019-10 8.0 3.0\n", | |
"8 2019-11 9.0 NaN\n", | |
"9 2019-12 10.0 5.0\n", | |
"10 2020-01 13.0 NaN\n", | |
"11 2020-02 14.0 14.0\n", | |
"12 2020-03 15.0 15.0\n", | |
"13 2020-04 NaN 17.0\n", | |
"14 2020-05 16.0 18.0" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pdf" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "6af32b55-f20c-4414-b6c2-343b74f8849e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>yr_month</th>\n", | |
" <th>part1</th>\n", | |
" <th>part2</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>2019-03</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2019-04</td>\n", | |
" <td>1.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>2019-05</td>\n", | |
" <td>1.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>2019-06</td>\n", | |
" <td>2.0</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>2019-07</td>\n", | |
" <td>2.0</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>2019-08</td>\n", | |
" <td>2.0</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>2019-09</td>\n", | |
" <td>4.0</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>2019-10</td>\n", | |
" <td>8.0</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>2019-11</td>\n", | |
" <td>9.0</td>\n", | |
" <td>3.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>2019-12</td>\n", | |
" <td>10.0</td>\n", | |
" <td>5.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>2020-01</td>\n", | |
" <td>13.0</td>\n", | |
" <td>5.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>2020-02</td>\n", | |
" <td>14.0</td>\n", | |
" <td>14.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>2020-03</td>\n", | |
" <td>15.0</td>\n", | |
" <td>15.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>2020-04</td>\n", | |
" <td>15.0</td>\n", | |
" <td>17.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>2020-05</td>\n", | |
" <td>16.0</td>\n", | |
" <td>18.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" yr_month part1 part2\n", | |
"0 2019-03 NaN 1.0\n", | |
"1 2019-04 1.0 1.0\n", | |
"2 2019-05 1.0 1.0\n", | |
"3 2019-06 2.0 1.0\n", | |
"4 2019-07 2.0 2.0\n", | |
"5 2019-08 2.0 2.0\n", | |
"6 2019-09 4.0 2.0\n", | |
"7 2019-10 8.0 3.0\n", | |
"8 2019-11 9.0 3.0\n", | |
"9 2019-12 10.0 5.0\n", | |
"10 2020-01 13.0 5.0\n", | |
"11 2020-02 14.0 14.0\n", | |
"12 2020-03 15.0 15.0\n", | |
"13 2020-04 15.0 17.0\n", | |
"14 2020-05 16.0 18.0" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pdf.ffill()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Py3.11 (sql_dev)", | |
"language": "python", | |
"name": "sql_dev" | |
}, | |
"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.11.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment