Skip to content

Instantly share code, notes, and snippets.

@rwcitek
Last active July 7, 2025 16:08
Show Gist options
  • Save rwcitek/2548f1b2b26127e1e5cc034912982032 to your computer and use it in GitHub Desktop.
Save rwcitek/2548f1b2b26127e1e5cc034912982032 to your computer and use it in GitHub Desktop.
abc-randoconverso-conversions-drills.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/rwcitek/2548f1b2b26127e1e5cc034912982032/abc-randoconverso-conversions-drills.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Hello There!"
],
"metadata": {
"id": "UzimTHqTpTod"
}
},
{
"cell_type": "markdown",
"source": [
"# Conversions\n",
"\n"
],
"metadata": {
"id": "vALWOTUM1cy_"
}
},
{
"cell_type": "markdown",
"source": [
"## Steps\n",
"\n"
],
"metadata": {
"id": "22AV3FyFIryl"
}
},
{
"cell_type": "markdown",
"source": [
"For each of the objects below:\n",
"\n",
"1. pick one\n",
"1. pick another one\n",
"1. create the first object\n",
"1. convert the first object to the second object\n",
"1. repeat\n",
"\n",
"\n"
],
"metadata": {
"id": "AFdZpEseI4oD"
}
},
{
"cell_type": "markdown",
"source": [
"## Objects\n",
"\n"
],
"metadata": {
"id": "iMR5yAJtInf3"
}
},
{
"cell_type": "markdown",
"source": [
"#ThanksFoundational\n",
"1. string\n",
"1. int\n",
"1. float\n",
"1. boolean\n",
"\n",
"Median\n",
"1. list\n",
"1. tuple\n",
"1. dictionary\n",
"1. set\n",
"\n",
"Advanced\n",
"1. numpy array\n",
"1. data series\n",
"1. data frame\n",
"\n"
],
"metadata": {
"id": "MWW-2khh1eeu"
}
},
{
"cell_type": "code",
"source": [
"import random\n",
"import string\n",
"import secrets\n",
"import numpy as np\n",
"import pandas as pd"
],
"metadata": {
"id": "Fy3K_HsCvwXz"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Define the data types to convert between, add to list\n",
"items = \"string int float boolean list tuple dictionary set np.array pd.series pd.dataframe\".split()\n",
"\n",
"# create an array of tuples that span all possible pairs to convert between\n",
"from_tos = []\n",
"x = 0\n",
"for i in items:\n",
" for k in items:\n",
" x += 1\n",
" from_tos.append((i, k))\n",
"\n",
"# create a conversion-pair dataframe from the tuple array\n",
"tos_pd = pd.DataFrame(from_tos)\n",
"\n",
"# create a column in the conversion-pair dataframe that will be how we track completed conversions\n",
"tos_pd[2] = 0\n",
"\n",
"# code to generate a random conversion-pair\n",
"i = np.random.randint(len(from_tos))\n",
"from_tos[i]"
],
"metadata": {
"id": "idL4MZKdKzUE",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "a708a0d9-a26d-4eb9-9dba-05601a250f77"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"('int', 'np.array')"
]
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"source": [
"# function that will generate only conversion-pairs that have not been marked as solved (via tos_pd.loc[2] where 0 = unsolved)\n",
"def rando_converso():\n",
" \"\"\"Creates a random pairing of data types to convert between,\n",
" and returns one where the value in column 2 is not equal to 1. (I.e., one that has not yet been completed.)\"\"\"\n",
" while True:\n",
" i = np.random.randint(len(from_tos))\n",
" raco = from_tos[i]\n",
"\n",
" value = tos_pd.loc[(tos_pd[0] == raco[0]) & (tos_pd[1] == raco[1]), 2] #while this is True (True = 1) continue to look for new pairs\n",
"\n",
" # Check that a result exists and its value is not equal to 1\n",
" if not value.empty and value.item() != 1:\n",
" return raco"
],
"metadata": {
"id": "d6ek4W3iMexI"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#Code block that will create randomly-generated datatypes for use during conversions\n",
"import random\n",
"import string\n",
"import secrets\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"# 1. Random String\n",
"random_string = ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(10)) # Using secrets for security\n",
"print(\"Random String:\", random_string)\n",
"\n",
"# 2. Random Float\n",
"random_float = random.uniform(0.0, 100.0) # Using uniform for a specified range\n",
"print(\"Random Float:\", random_float)\n",
"\n",
"# 3. Random Integer\n",
"random_integer = random.randint(1, 100)\n",
"print(\"Random Integer:\", random_integer)\n",
"\n",
"# 4. Random Boolean\n",
"random_boolean = random.choice([True, False])\n",
"print(\"Random Boolean:\", random_boolean)\n",
"\n",
"# 5. Random List\n",
"random_list = [random.randint(1, 10) for _ in range(5)]\n",
"print(\"Random List:\", random_list)\n",
"\n",
"# 6. Random Set (requires unique elements, so generate a list first)\n",
"random_list_for_set = random.sample(range(1, 101), 5) # Sample ensures unique elements\n",
"random_set = set(random_list_for_set)\n",
"print(\"Random Set:\", random_set)\n",
"\n",
"# 7. Random Dictionary\n",
"random_dict = {f\"key_{i}\": random.randint(1, 100) for i in range(3)}\n",
"print(\"Random Dictionary:\", random_dict)\n",
"\n",
"# 8. Random Tuple\n",
"random_tuple = tuple(random.randint(1, 10) for _ in range(5))\n",
"print(\"Random Tuple:\", random_tuple)\n",
"\n",
"# 9. Random NumPy Array\n",
"random_numpy_array = np.random.randint(0, 10, size=(3, 4))\n",
"print(\"\\nRandom NumPy Array:\\n\", random_numpy_array)\n",
"\n",
"# 10. Random Pandas Series\n",
"random_pandas_series = pd.Series(np.random.randn(10))\n",
"print(\"\\nRandom Pandas Series:\\n\", random_pandas_series)\n",
"\n",
"# 11. Random Pandas DataFrame\n",
"random_pandas_df = pd.DataFrame(np.random.randint(0, 100, size=(5, 3)), columns=list('ABC'))\n",
"print(\"\\nRandom Pandas DataFrame:\\n\", random_pandas_df)"
],
"metadata": {
"id": "4StF919VMIXd",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "7a74e842-4e1a-4b74-b834-6b864a13060f"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Random String: SZZCG4JDSM\n",
"Random Float: 48.81184311272234\n",
"Random Integer: 55\n",
"Random Boolean: True\n",
"Random List: [10, 4, 4, 6, 7]\n",
"Random Set: {35, 9, 11, 25, 94}\n",
"Random Dictionary: {'key_0': 21, 'key_1': 86, 'key_2': 79}\n",
"Random Tuple: (9, 7, 6, 3, 9)\n",
"\n",
"Random NumPy Array:\n",
" [[9 6 3 8]\n",
" [7 5 4 3]\n",
" [1 1 3 7]]\n",
"\n",
"Random Pandas Series:\n",
" 0 -0.661923\n",
"1 1.402785\n",
"2 0.344537\n",
"3 0.875660\n",
"4 0.793822\n",
"5 0.332489\n",
"6 -0.593308\n",
"7 -0.346166\n",
"8 -0.321244\n",
"9 -1.665646\n",
"dtype: float64\n",
"\n",
"Random Pandas DataFrame:\n",
" A B C\n",
"0 38 76 36\n",
"1 52 80 19\n",
"2 63 5 39\n",
"3 46 81 79\n",
"4 60 53 71\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"## Code block that is broken into 2 parts: Part 1 finds an unsolved conversion, Part 2 should be run when the conversion has been successful to mark it as solved\n",
"## Usage Procedure, Ordered Steps: 1. Uncomment Part 1 and run, then set back to comment; 2. Copy the generated unsolved conversion-pair and paste into Part 2 line 1; 3. Solve the conversion; 4. Uncomment Part 2 and run to mark the conversion as solved, then leave uncommented so it will run next time you open the notebook\n",
"\n",
"##Part 1: Run these two lines to generate an unsolved conversion-pair\n",
"# rando = rando_converso()\n",
"# print(f'rando = {rando}')\n",
"\n",
"##Part 2: Run these 6 lines to mark the conversion-pair in the 1st line as solved in the conversion-pair dataframe\n",
"# rando = ('replace1', 'replace2') # replace these with the conversion-pair generated from Part 1, above\n",
"# print(rando)\n",
"# r1 = rando[0]\n",
"# r2 = rando[1]\n",
"# tos_pd.loc[(tos_pd[0] == r1) & (tos_pd[1] == r2), 2] = 1\n",
"# f'Total completed: {tos_pd[2].sum()}'"
],
"metadata": {
"id": "D3ZZNpoaNoJW"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"##Example"
],
"metadata": {
"id": "AvaWF7WZXuu2"
}
},
{
"cell_type": "markdown",
"source": [
"This is the base code to copy & paste into each new conversion:"
],
"metadata": {
"id": "dK8FKz1dZizN"
}
},
{
"cell_type": "code",
"source": [
"## Code block that is broken into 2 parts: Part 1 finds an unsolved conversion, Part 2 should be run when the conversion has been successful to mark it as solved\n",
"## Usage Procedure, Ordered Steps: 1. Uncomment Part 1 and run, then set back to comment; 2. Copy the generated unsolved conversion-pair and paste into Part 2 line 1; 3. Solve the conversion; 4. Uncomment Part 2 and run to mark the conversion as solved, then leave uncommented so it will run next time you open the notebook\n",
"\n",
"##Part 1: Run these two lines to generate an unsolved conversion-pair\n",
"# rando = rando_converso()\n",
"# print(f'rando = {rando}')\n",
"\n",
"##Part 2: Run these 6 lines to mark the conversion-pair in the 1st line as solved in the conversion-pair dataframe\n",
"# rando = ('replace1', 'replace2') # replace these with the conversion-pair generated from Part 1, above\n",
"# print(rando)\n",
"# r1 = rando[0]\n",
"# r2 = rando[1]\n",
"# tos_pd.loc[(tos_pd[0] == r1) & (tos_pd[1] == r2), 2] = 1\n",
"# f'Total completed: {tos_pd[2].sum()}'"
],
"metadata": {
"id": "aPlT2DpCX4vE"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"This would be the first step, uncomment Part 1 and run it, then re-comment it"
],
"metadata": {
"id": "mnEk-0XpZpZm"
}
},
{
"cell_type": "code",
"source": [
"#Part 1: Run these two lines to generate an unsolved conversion-pair\n",
"rando = rando_converso()\n",
"print(f'rando = {rando}')\n",
"\n",
"##Part 2: Run these 6 lines to mark the conversion-pair in the 1st line as solved in the conversion-pair dataframe\n",
"# rando = ('replace1', 'replace2') # replace these with the conversion-pair generated from Part 1, above\n",
"# print(rando)\n",
"# r1 = rando[0]\n",
"# r2 = rando[1]\n",
"# tos_pd.loc[(tos_pd[0] == r1) & (tos_pd[1] == r2), 2] = 1\n",
"# f'Total completed: {tos_pd[2].sum()}'"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wN6uwI63X74T",
"outputId": "c855b07a-7f02-48a9-9ec9-54257ee76972"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"rando = ('int', 'dictionary')\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"- Let's pretent that we got rando = ('float', 'int')\n",
"- Copy & Paste this Tuple into this Part 2 section: ('replace1', 'replace2')\n",
"- From here, we will do the conversion"
],
"metadata": {
"id": "FV9kAOxqZwq4"
}
},
{
"cell_type": "code",
"source": [
"#The code earlier in this notebook will create a set of random datatypes with the random_ prefix\n",
"random_float"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "t2geWILGaq83",
"outputId": "02e69f5c-a224-443f-e49d-e31e02e9965c"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"48.81184311272234"
]
},
"metadata": {},
"execution_count": 8
}
]
},
{
"cell_type": "code",
"source": [
"int(random_float)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ndeLL-0QYk--",
"outputId": "35ed660e-85eb-4def-b80f-864fbbd1ea1a"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"48"
]
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "markdown",
"source": [
"- Now that we have this conversion pair solved, we can uncomment and run Part 2\n",
"- Note: Leave this Part 2 with your recently-solved conversion uncommented, so it will run next time you open the notebook\n",
"\n"
],
"metadata": {
"id": "T65Yep1Rbbm6"
}
},
{
"cell_type": "code",
"source": [
"# #Part 1: Run these two lines to generate an unsolved conversion-pair\n",
"# rando = rando_converso()\n",
"# print(f'rando = {rando}')\n",
"\n",
"#Part 2: Run these 6 lines to mark the conversion-pair in the 1st line as solved in the conversion-pair dataframe\n",
"rando = ('float', 'int') # replace these with the conversion-pair generated from Part 1, above\n",
"print(rando)\n",
"r1 = rando[0]\n",
"r2 = rando[1]\n",
"tos_pd.loc[(tos_pd[0] == r1) & (tos_pd[1] == r2), 2] = 1\n",
"f'Total completed: {tos_pd[2].sum()}'"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 53
},
"id": "21wpg4B6aqDG",
"outputId": "1553186b-5fbb-442f-f59e-f67086371ab4"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"('float', 'int')\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'Total completed: 1'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "markdown",
"source": [
"Now we have 1 completed conversion! You can see this in the tos_pd"
],
"metadata": {
"id": "Ny9NUPbyb0st"
}
},
{
"cell_type": "code",
"source": [
"tos_pd"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "aaOQSA6Zcc5N",
"outputId": "68b3c495-0d23-4f31-b0f3-967f999118a1"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 0 1 2\n",
"0 string string 0\n",
"1 string int 0\n",
"2 string float 0\n",
"3 string boolean 0\n",
"4 string list 0\n",
".. ... ... ..\n",
"116 pd.dataframe dictionary 0\n",
"117 pd.dataframe set 0\n",
"118 pd.dataframe np.array 0\n",
"119 pd.dataframe pd.series 0\n",
"120 pd.dataframe pd.dataframe 0\n",
"\n",
"[121 rows x 3 columns]"
],
"text/html": [
"\n",
" <div id=\"df-4f076f4d-013e-4f6b-8db9-affa66d8f567\" class=\"colab-df-container\">\n",
" <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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>string</td>\n",
" <td>string</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>string</td>\n",
" <td>int</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>string</td>\n",
" <td>float</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>string</td>\n",
" <td>boolean</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>string</td>\n",
" <td>list</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>pd.dataframe</td>\n",
" <td>dictionary</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>pd.dataframe</td>\n",
" <td>set</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>pd.dataframe</td>\n",
" <td>np.array</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>pd.dataframe</td>\n",
" <td>pd.series</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>pd.dataframe</td>\n",
" <td>pd.dataframe</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>121 rows × 3 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-4f076f4d-013e-4f6b-8db9-affa66d8f567')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-4f076f4d-013e-4f6b-8db9-affa66d8f567 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-4f076f4d-013e-4f6b-8db9-affa66d8f567');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
" <div id=\"df-cace9f73-ba17-45e2-9784-23f3d6fdfd72\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-cace9f73-ba17-45e2-9784-23f3d6fdfd72')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-cace9f73-ba17-45e2-9784-23f3d6fdfd72 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" <div id=\"id_7c0aa2ef-9130-4f7b-8cf1-fc12f987f817\">\n",
" <style>\n",
" .colab-df-generate {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-generate:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('tos_pd')\"\n",
" title=\"Generate code using this dataframe.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
" </svg>\n",
" </button>\n",
" <script>\n",
" (() => {\n",
" const buttonEl =\n",
" document.querySelector('#id_7c0aa2ef-9130-4f7b-8cf1-fc12f987f817 button.colab-df-generate');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" buttonEl.onclick = () => {\n",
" google.colab.notebook.generateWithVariable('tos_pd');\n",
" }\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"variable_name": "tos_pd",
"summary": "{\n \"name\": \"tos_pd\",\n \"rows\": 121,\n \"fields\": [\n {\n \"column\": 0,\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 11,\n \"samples\": [\n \"tuple\",\n \"string\",\n \"pd.series\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": 1,\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 11,\n \"samples\": [\n \"tuple\",\n \"string\",\n \"pd.series\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": 2,\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 1,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"source": [
"tos_pd.iloc[[23]]"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 81
},
"id": "QI-AeP42bpZK",
"outputId": "04de6b41-2306-4a75-f1d9-bef4cc7f1256"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" 0 1 2\n",
"23 float int 1"
],
"text/html": [
"\n",
" <div id=\"df-609792a4-172d-43f0-a86c-9ac5d8d505e2\" class=\"colab-df-container\">\n",
" <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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>float</td>\n",
" <td>int</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-609792a4-172d-43f0-a86c-9ac5d8d505e2')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-609792a4-172d-43f0-a86c-9ac5d8d505e2 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-609792a4-172d-43f0-a86c-9ac5d8d505e2');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"summary": "{\n \"name\": \"tos_pd\",\n \"rows\": 1,\n \"fields\": [\n {\n \"column\": 0,\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"float\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": 1,\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"int\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": 2,\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 1,\n \"max\": 1,\n \"num_unique_values\": 1,\n \"samples\": [\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "markdown",
"source": [
"And that's it! Copy and paste the cell below and run it for each new conversion pair using the process described, above, and it will only generate new conversion pairs."
],
"metadata": {
"id": "v3L2EYhEci3_"
}
},
{
"cell_type": "code",
"source": [
"## Code block that is broken into 2 parts: Part 1 finds an unsolved conversion, Part 2 should be run when the conversion has been successful to mark it as solved\n",
"## Usage Procedure, Ordered Steps: 1. Uncomment Part 1 and run, then set back to comment; 2. Copy the generated unsolved conversion-pair and paste into Part 2 line 1; 3. Solve the conversion; 4. Uncomment Part 2 and run to mark the conversion as solved, then leave uncommented so it will run next time you open the notebook\n",
"\n",
"##Part 1: Run these two lines to generate an unsolved conversion-pair\n",
"# rando = rando_converso()\n",
"# print(f'rando = {rando}')\n",
"\n",
"##Part 2: Run these 6 lines to mark the conversion-pair in the 1st line as solved in the conversion-pair dataframe\n",
"# rando = ('replace1', 'replace2') # replace these with the conversion-pair generated from Part 1, above\n",
"# print(rando)\n",
"# r1 = rando[0]\n",
"# r2 = rando[1]\n",
"# tos_pd.loc[(tos_pd[0] == r1) & (tos_pd[1] == r2), 2] = 1\n",
"# f'Total completed: {tos_pd[2].sum()}'"
],
"metadata": {
"id": "QbK3FmEmcusS"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment