{
  "id": 324483,
  "title": "I Created a Dataset with all the Training Data as a CSV (json --> csv)",
  "url": "/competitions/AI4Code/discussion/324483",
  "author_name": "",
  "post_date": "2022-05-12T01:10:23.509509200Z",
  "votes": 52,
  "comment_count": 17,
  "views": 0,
  "content": "<p><strong>[EDIT/UPDATE]</strong></p>\n<hr>\n<p>There are a few important updates. </p>\n<ol>\n<li>When <strong>SAVING</strong> the <strong><code>pd.Dataframe</code></strong> as a <strong><code>.csv</code></strong>, the following command should be used to avoid improper interpretation of newline character(s). </li>\n</ol>\n<pre><code>train_df.to_csv(\n    \"train.csv\", index=False, \n    encoding='utf-8', \n    quoting=csv.QUOTE_NONNUMERIC   # &lt;== THIS IS REQUIRED\n)\n</code></pre>\n<ol>\n<li>When <strong>LOADING</strong> the <strong><code>.csv</code></strong> as a <strong><code>pd.Dataframe</code></strong>, the following command must be used to avoid misinterpretation of <strong><code>NaN</code></strong> like strings (null, nan, …) as <strong><code>pd.NaN</code></strong> values.</li>\n</ol>\n<pre><code>train_df = pd.read_csv(\n    \"/kaggle/input/ai4code-train-dataframe/train.csv\", \n    keep_default_na=False   # &lt;== THIS IS REQUIRED\n)\n</code></pre>\n<hr>\n<p><br></p>\n<p><strong>[ORIGINAL POST]</strong></p>\n<p>As the title says. I generated a csv/pd.Dataframe from the raw json files. This will save you 20-30 minutes of processing if you do it yourself. </p>\n<p>Here is the <a href=\"https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe\" target=\"_blank\"><strong>dataset link</strong></a> containing the <strong><code>train.csv</code></strong> file.</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe\" target=\"_blank\"><strong>DATASET LINK</strong></a></li>\n</ul>\n<p>Here is the code used to generate the pd.DataFrame which was then saved as a csv. </p>\n<ul>\n<li>Note that I also reorder the columns to better reflect the inherent structure.</li>\n</ul>\n<p><strong>[UPDATED CODE TO REMOVE JOBLIB]</strong></p>\n<pre><code>def load_json_to_df(all_fpaths):\n    def __fpath_to_df(fpath):\n        tmp_df = pd.read_json(fpath, dtype={'cell_type': 'category', 'source': 'str'}).reset_index().rename({\"index\":\"cell_id\"}, axis=1)\n        tmp_df[\"id\"] = fpath.rsplit(\".\", 1)[0].rsplit(\"/\", 1)[-1]\n        return tmp_df\n    all_example_dfs = [__fpath_to_df(fpath) for fpath in tqdm(all_fpaths, total=len(all_fpaths))]\n    return pd.concat(all_example_dfs).reset_index(drop=True)\n</code></pre>\n<p>You can also see this code within my in-progress <a href=\"https://www.kaggle.com/dschettler8845/ai4code-eda-baseline\" target=\"_blank\"><strong>EDA Notebook</strong></a></p>\n<ul>\n<li>This may not be available for a few minutes as I'm in the process of making it public.</li>\n</ul>",
  "messages": [
    {
      "id": "1785274",
      "postDate": "05/12/2022 01:10:23",
      "content": "<p><strong>[EDIT/UPDATE]</strong></p>\n<hr>\n<p>There are a few important updates. </p>\n<ol>\n<li>When <strong>SAVING</strong> the <strong><code>pd.Dataframe</code></strong> as a <strong><code>.csv</code></strong>, the following command should be used to avoid improper interpretation of newline character(s). </li>\n</ol>\n<pre><code>train_df.to_csv(\n    \"train.csv\", index=False, \n    encoding='utf-8', \n    quoting=csv.QUOTE_NONNUMERIC   # &lt;== THIS IS REQUIRED\n)\n</code></pre>\n<ol>\n<li>When <strong>LOADING</strong> the <strong><code>.csv</code></strong> as a <strong><code>pd.Dataframe</code></strong>, the following command must be used to avoid misinterpretation of <strong><code>NaN</code></strong> like strings (null, nan, …) as <strong><code>pd.NaN</code></strong> values.</li>\n</ol>\n<pre><code>train_df = pd.read_csv(\n    \"/kaggle/input/ai4code-train-dataframe/train.csv\", \n    keep_default_na=False   # &lt;== THIS IS REQUIRED\n)\n</code></pre>\n<hr>\n<p><br></p>\n<p><strong>[ORIGINAL POST]</strong></p>\n<p>As the title says. I generated a csv/pd.Dataframe from the raw json files. This will save you 20-30 minutes of processing if you do it yourself. </p>\n<p>Here is the <a href=\"https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe\" target=\"_blank\"><strong>dataset link</strong></a> containing the <strong><code>train.csv</code></strong> file.</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe\" target=\"_blank\"><strong>DATASET LINK</strong></a></li>\n</ul>\n<p>Here is the code used to generate the pd.DataFrame which was then saved as a csv. </p>\n<ul>\n<li>Note that I also reorder the columns to better reflect the inherent structure.</li>\n</ul>\n<p><strong>[UPDATED CODE TO REMOVE JOBLIB]</strong></p>\n<pre><code>def load_json_to_df(all_fpaths):\n    def __fpath_to_df(fpath):\n        tmp_df = pd.read_json(fpath, dtype={'cell_type': 'category', 'source': 'str'}).reset_index().rename({\"index\":\"cell_id\"}, axis=1)\n        tmp_df[\"id\"] = fpath.rsplit(\".\", 1)[0].rsplit(\"/\", 1)[-1]\n        return tmp_df\n    all_example_dfs = [__fpath_to_df(fpath) for fpath in tqdm(all_fpaths, total=len(all_fpaths))]\n    return pd.concat(all_example_dfs).reset_index(drop=True)\n</code></pre>\n<p>You can also see this code within my in-progress <a href=\"https://www.kaggle.com/dschettler8845/ai4code-eda-baseline\" target=\"_blank\"><strong>EDA Notebook</strong></a></p>\n<ul>\n<li>This may not be available for a few minutes as I'm in the process of making it public.</li>\n</ul>",
      "rawMarkdown": "**[EDIT/UPDATE]**\n\n---\n\nThere are a few important updates. \n\n1. When **SAVING** the **`pd.Dataframe`** as a **`.csv`**, the following command should be used to avoid improper interpretation of newline character(s). \n\n```python\ntrain_df.to_csv(\n    \"train.csv\", index=False, \n    encoding='utf-8', \n    quoting=csv.QUOTE_NONNUMERIC   # <== THIS IS REQUIRED\n)\n```\n\n\n2. When **LOADING** the **`.csv`** as a **`pd.Dataframe`**, the following command must be used to avoid misinterpretation of **`NaN`** like strings (null, nan, ...) as **`pd.NaN`** values.\n\n```python\ntrain_df = pd.read_csv(\n    \"/kaggle/input/ai4code-train-dataframe/train.csv\", \n    keep_default_na=False   # <== THIS IS REQUIRED\n)\n```\n\n---\n\n<br>\n\n**[ORIGINAL POST]**\n\nAs the title says. I generated a csv/pd.Dataframe from the raw json files. This will save you 20-30 minutes of processing if you do it yourself. \n\nHere is the [**dataset link**](https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe) containing the **`train.csv`** file.\n* [**DATASET LINK**](https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe)\n\nHere is the code used to generate the pd.DataFrame which was then saved as a csv. \n* Note that I also reorder the columns to better reflect the inherent structure.\n\n**[UPDATED CODE TO REMOVE JOBLIB]**\n\n```python\ndef load_json_to_df(all_fpaths):\n    def __fpath_to_df(fpath):\n        tmp_df = pd.read_json(fpath, dtype={'cell_type': 'category', 'source': 'str'}).reset_index().rename({\"index\":\"cell_id\"}, axis=1)\n        tmp_df[\"id\"] = fpath.rsplit(\".\", 1)[0].rsplit(\"/\", 1)[-1]\n        return tmp_df\n    all_example_dfs = [__fpath_to_df(fpath) for fpath in tqdm(all_fpaths, total=len(all_fpaths))]\n    return pd.concat(all_example_dfs).reset_index(drop=True)\n```\n\nYou can also see this code within my in-progress [**EDA Notebook**](https://www.kaggle.com/dschettler8845/ai4code-eda-baseline)\n* This may not be available for a few minutes as I'm in the process of making it public.",
      "votes": null
    },
    {
      "id": "1785288",
      "postDate": "05/12/2022 01:56:04",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nThere are 12 NA values in the train dataframe. <br>\nIndexes of missing values - 154891, 154891, 1305172, 1305172, 1373663, 1373663, 2076839, 2915102, 3416953, 4260449, 6154217, 6154217.</p>",
      "rawMarkdown": "dschettler8845 \nThere are 12 NA values in the train dataframe. \nIndexes of missing values - 154891, 154891, 1305172, 1305172, 1373663, 1373663, 2076839, 2915102, 3416953, 4260449, 6154217, 6154217.",
      "votes": null
    },
    {
      "id": "1785294",
      "postDate": "05/12/2022 02:08:08",
      "content": "<p>Let me check that and get back to you. Thanks for pointing it out.</p>",
      "rawMarkdown": "Let me check that and get back to you. Thanks for pointing it out.",
      "votes": null
    },
    {
      "id": "1785295",
      "postDate": "05/12/2022 02:12:20",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> thanks for that!</p>",
      "rawMarkdown": "dschettler8845 thanks for that!",
      "votes": null
    },
    {
      "id": "1785297",
      "postDate": "05/12/2022 02:13:50",
      "content": "<p>Ok, so it looks like I messed up during multiprocessing and it added an empty string <strong><code>id</code></strong> that has a few values. I'm not sure if this is an extra addition or if valuable information was overwritten. I will check this and get back. </p>\n<p>The <strong><code>iloc</code></strong> values exhibiting this are the following</p>\n<ul>\n<li>154891, 1305172, 1373663, 6154217</li>\n</ul>\n<p>The other numbers you mentioned look to be related to the source information being missing. I will also investigate this and get back to you.</p>",
      "rawMarkdown": "Ok, so it looks like I messed up during multiprocessing and it added an empty string **`id`** that has a few values. I'm not sure if this is an extra addition or if valuable information was overwritten. I will check this and get back. \n\nThe **`iloc`** values exhibiting this are the following\n* 154891, 1305172, 1373663, 6154217\n\nThe other numbers you mentioned look to be related to the source information being missing. I will also investigate this and get back to you.",
      "votes": null
    },
    {
      "id": "1785942",
      "postDate": "05/12/2022 14:02:19",
      "content": "<p>Great dataset!</p>",
      "rawMarkdown": "Great dataset!",
      "votes": null
    },
    {
      "id": "1786073",
      "postDate": "05/12/2022 15:31:58",
      "content": "<p>Ok, I have rerun without the parallelization and all the nan values are gone. I am updating the dataset as we speak to be correct. Thanks again for catching this!</p>\n<p>[EDIT] </p>\n<p>It appears that while the NaN values do not exist after parsing… after saving and then loading the csv directly they appear. I am troubleshooting this now and will update it shortly with the corrected version (ETA May 12 ~2PM EST).</p>\n<p>[EDIT 2] </p>\n<p>It appears that there were two problems:</p>\n<ol>\n<li><p>The newline character in some code cells is interpreted during saving and results in the creation of a new row that doesn't exist (this usually can be seen as a row with &gt; and all nan values). <strong>I have recreated the dataset and used a different newline interpreter to avoid this.</strong></p></li>\n<li><p>The interpretation during loading of certain strings as NaN instead of the string representation. i.e. the code block contains only the text \"null\" but pandas interpret this as pd.NaN. This can be avoided by specifying <strong><code>keep_default_na=False</code></strong> in the <strong><code>pd.read_csv()</code></strong> command (i.e. no default NaN parsing). I will update the main body of the post with information about specifying this command when loading.</p></li>\n</ol>\n<hr>\n<p>I hope this clears everything up!</p>",
      "rawMarkdown": "Ok, I have rerun without the parallelization and all the nan values are gone. I am updating the dataset as we speak to be correct. Thanks again for catching this!\n\n[EDIT] \n\nIt appears that while the NaN values do not exist after parsing... after saving and then loading the csv directly they appear. I am troubleshooting this now and will update it shortly with the corrected version (ETA May 12 ~2PM EST).\n\n[EDIT 2] \n\nIt appears that there were two problems:\n\n1. The newline character in some code cells is interpreted during saving and results in the creation of a new row that doesn't exist (this usually can be seen as a row with > and all nan values). **I have recreated the dataset and used a different newline interpreter to avoid this.**\n\n2. The interpretation during loading of certain strings as NaN instead of the string representation. i.e. the code block contains only the text \"null\" but pandas interpret this as pd.NaN. This can be avoided by specifying **`keep_default_na=False`** in the **`pd.read_csv()`** command (i.e. no default NaN parsing). I will update the main body of the post with information about specifying this command when loading.\n\n---\n\nI hope this clears everything up!",
      "votes": null
    },
    {
      "id": "1786136",
      "postDate": "05/12/2022 16:19:36",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nwhile extracting <code>id</code> there is <code>dot(.)</code> comming with <code>id</code> Ex (<code>8a2564b730a575.</code>)<br>\nQuickFix : </p>\n<pre><code>tmp_df[\"id\"] = fpath[:-4].rsplit(\"/\", 1)[-1].strip('.')\n</code></pre>\n<p>Thanks for the nice code :) </p>",
      "rawMarkdown": "dschettler8845 \nwhile extracting `id` there is `dot(.)` comming with `id` Ex (`8a2564b730a575.`)\nQuickFix : \n````python\ntmp_df[\"id\"] = fpath[:-4].rsplit(\"/\", 1)[-1].strip('.')\n````\nThanks for the nice code :)",
      "votes": null
    },
    {
      "id": "1786198",
      "postDate": "05/12/2022 17:06:11",
      "content": "<p>That should be fixed now. My apologies!</p>",
      "rawMarkdown": "That should be fixed now. My apologies!",
      "votes": null
    },
    {
      "id": "1786214",
      "postDate": "05/12/2022 17:30:20",
      "content": "<p>Thanks for the update <a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nI am dropping null values in my notebook. This will most probably have no effects after any updates in the dataset versions.</p>",
      "rawMarkdown": "Thanks for the update @dschettler8845 \nI am dropping null values in my notebook. This will most probably have no effects after any updates in the dataset versions.",
      "votes": null
    },
    {
      "id": "1786562",
      "postDate": "05/13/2022 02:42:37",
      "content": "<p>Hey! Nice work. Looks like we had the same idea. I ran the process on my twitch stream tonight and created a parquet version too. If people find it helpful it's here: <a href=\"https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular\" target=\"_blank\">https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular</a></p>",
      "rawMarkdown": "Hey! Nice work. Looks like we had the same idea. I ran the process on my twitch stream tonight and created a parquet version too. If people find it helpful it's here: https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular",
      "votes": null
    },
    {
      "id": "1789514",
      "postDate": "05/14/2022 01:09:37",
      "content": "<p>thank you for your work, I was gonna do it myself but I am glad I don't have to lol.</p>",
      "rawMarkdown": "thank you for your work, I was gonna do it myself but I am glad I don't have to lol.",
      "votes": null
    },
    {
      "id": "1789950",
      "postDate": "05/14/2022 11:26:34",
      "content": "<p>Nice work:)</p>",
      "rawMarkdown": "Nice work:)",
      "votes": null
    },
    {
      "id": "1790323",
      "postDate": "05/14/2022 19:14:00",
      "content": "<p>Nice! I love your streams!</p>",
      "rawMarkdown": "Nice! I love your streams!",
      "votes": null
    },
    {
      "id": "1790324",
      "postDate": "05/14/2022 19:14:19",
      "content": "<p>You're welcome! glad I could help :)</p>",
      "rawMarkdown": "You're welcome! glad I could help :)",
      "votes": null
    },
    {
      "id": "1790325",
      "postDate": "05/14/2022 19:14:26",
      "content": "<p>Thank you ! Glad to help!</p>",
      "rawMarkdown": "Thank you ! Glad to help!",
      "votes": null
    },
    {
      "id": "1790326",
      "postDate": "05/14/2022 19:14:38",
      "content": "<p>Thank you, glad I could help!</p>",
      "rawMarkdown": "Thank you, glad I could help!",
      "votes": null
    },
    {
      "id": "1790327",
      "postDate": "05/14/2022 19:14:46",
      "content": "<p>Hahaha yes! That's the idea. :)</p>",
      "rawMarkdown": "Hahaha yes! That's the idea. :)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1785288,
      "author_name": "odins0n",
      "author_url": "",
      "post_date": "05/12/2022 01:56:04",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nThere are 12 NA values in the train dataframe. <br>\nIndexes of missing values - 154891, 154891, 1305172, 1305172, 1373663, 1373663, 2076839, 2915102, 3416953, 4260449, 6154217, 6154217.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1785294,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/12/2022 02:08:08",
          "content": "<p>Let me check that and get back to you. Thanks for pointing it out.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1785297,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/12/2022 02:13:50",
          "content": "<p>Ok, so it looks like I messed up during multiprocessing and it added an empty string <strong><code>id</code></strong> that has a few values. I'm not sure if this is an extra addition or if valuable information was overwritten. I will check this and get back. </p>\n<p>The <strong><code>iloc</code></strong> values exhibiting this are the following</p>\n<ul>\n<li>154891, 1305172, 1373663, 6154217</li>\n</ul>\n<p>The other numbers you mentioned look to be related to the source information being missing. I will also investigate this and get back to you.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1786073,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/12/2022 15:31:58",
          "content": "<p>Ok, I have rerun without the parallelization and all the nan values are gone. I am updating the dataset as we speak to be correct. Thanks again for catching this!</p>\n<p>[EDIT] </p>\n<p>It appears that while the NaN values do not exist after parsing… after saving and then loading the csv directly they appear. I am troubleshooting this now and will update it shortly with the corrected version (ETA May 12 ~2PM EST).</p>\n<p>[EDIT 2] </p>\n<p>It appears that there were two problems:</p>\n<ol>\n<li><p>The newline character in some code cells is interpreted during saving and results in the creation of a new row that doesn't exist (this usually can be seen as a row with &gt; and all nan values). <strong>I have recreated the dataset and used a different newline interpreter to avoid this.</strong></p></li>\n<li><p>The interpretation during loading of certain strings as NaN instead of the string representation. i.e. the code block contains only the text \"null\" but pandas interpret this as pd.NaN. This can be avoided by specifying <strong><code>keep_default_na=False</code></strong> in the <strong><code>pd.read_csv()</code></strong> command (i.e. no default NaN parsing). I will update the main body of the post with information about specifying this command when loading.</p></li>\n</ol>\n<hr>\n<p>I hope this clears everything up!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1786214,
          "author_name": "odins0n",
          "author_url": "",
          "post_date": "05/12/2022 17:30:20",
          "content": "<p>Thanks for the update <a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nI am dropping null values in my notebook. This will most probably have no effects after any updates in the dataset versions.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1785295,
      "author_name": "lachlangillian",
      "author_url": "",
      "post_date": "05/12/2022 02:12:20",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> thanks for that!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1790324,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/14/2022 19:14:19",
          "content": "<p>You're welcome! glad I could help :)</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1785942,
      "author_name": "",
      "author_url": "",
      "post_date": "05/12/2022 14:02:19",
      "content": "<p>Great dataset!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1790325,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/14/2022 19:14:26",
          "content": "<p>Thank you ! Glad to help!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1786136,
      "author_name": "coolcoder22",
      "author_url": "",
      "post_date": "05/12/2022 16:19:36",
      "content": "<p><a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> <br>\nwhile extracting <code>id</code> there is <code>dot(.)</code> comming with <code>id</code> Ex (<code>8a2564b730a575.</code>)<br>\nQuickFix : </p>\n<pre><code>tmp_df[\"id\"] = fpath[:-4].rsplit(\"/\", 1)[-1].strip('.')\n</code></pre>\n<p>Thanks for the nice code :) </p>",
      "votes": null,
      "replies": [
        {
          "id": 1786198,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/12/2022 17:06:11",
          "content": "<p>That should be fixed now. My apologies!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1786562,
      "author_name": "robikscube",
      "author_url": "",
      "post_date": "05/13/2022 02:42:37",
      "content": "<p>Hey! Nice work. Looks like we had the same idea. I ran the process on my twitch stream tonight and created a parquet version too. If people find it helpful it's here: <a href=\"https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular\" target=\"_blank\">https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1790323,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/14/2022 19:14:00",
          "content": "<p>Nice! I love your streams!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1789514,
      "author_name": "bluetriad",
      "author_url": "",
      "post_date": "05/14/2022 01:09:37",
      "content": "<p>thank you for your work, I was gonna do it myself but I am glad I don't have to lol.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1790327,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/14/2022 19:14:46",
          "content": "<p>Hahaha yes! That's the idea. :)</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1789950,
      "author_name": "happylive",
      "author_url": "",
      "post_date": "05/14/2022 11:26:34",
      "content": "<p>Nice work:)</p>",
      "votes": null,
      "replies": [
        {
          "id": 1790326,
          "author_name": "dschettler8845",
          "author_url": "",
          "post_date": "05/14/2022 19:14:38",
          "content": "<p>Thank you, glad I could help!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1785274": "**[EDIT/UPDATE]**\n\n---\n\nThere are a few important updates. \n\n1. When **SAVING** the **`pd.Dataframe`** as a **`.csv`**, the following command should be used to avoid improper interpretation of newline character(s). \n\n```python\ntrain_df.to_csv(\n    \"train.csv\", index=False, \n    encoding='utf-8', \n    quoting=csv.QUOTE_NONNUMERIC   # <== THIS IS REQUIRED\n)\n```\n\n\n2. When **LOADING** the **`.csv`** as a **`pd.Dataframe`**, the following command must be used to avoid misinterpretation of **`NaN`** like strings (null, nan, ...) as **`pd.NaN`** values.\n\n```python\ntrain_df = pd.read_csv(\n    \"/kaggle/input/ai4code-train-dataframe/train.csv\", \n    keep_default_na=False   # <== THIS IS REQUIRED\n)\n```\n\n---\n\n<br>\n\n**[ORIGINAL POST]**\n\nAs the title says. I generated a csv/pd.Dataframe from the raw json files. This will save you 20-30 minutes of processing if you do it yourself. \n\nHere is the [**dataset link**](https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe) containing the **`train.csv`** file.\n* [**DATASET LINK**](https://www.kaggle.com/datasets/dschettler8845/ai4code-train-dataframe)\n\nHere is the code used to generate the pd.DataFrame which was then saved as a csv. \n* Note that I also reorder the columns to better reflect the inherent structure.\n\n**[UPDATED CODE TO REMOVE JOBLIB]**\n\n```python\ndef load_json_to_df(all_fpaths):\n    def __fpath_to_df(fpath):\n        tmp_df = pd.read_json(fpath, dtype={'cell_type': 'category', 'source': 'str'}).reset_index().rename({\"index\":\"cell_id\"}, axis=1)\n        tmp_df[\"id\"] = fpath.rsplit(\".\", 1)[0].rsplit(\"/\", 1)[-1]\n        return tmp_df\n    all_example_dfs = [__fpath_to_df(fpath) for fpath in tqdm(all_fpaths, total=len(all_fpaths))]\n    return pd.concat(all_example_dfs).reset_index(drop=True)\n```\n\nYou can also see this code within my in-progress [**EDA Notebook**](https://www.kaggle.com/dschettler8845/ai4code-eda-baseline)\n* This may not be available for a few minutes as I'm in the process of making it public.",
    "1785288": "dschettler8845 \nThere are 12 NA values in the train dataframe. \nIndexes of missing values - 154891, 154891, 1305172, 1305172, 1373663, 1373663, 2076839, 2915102, 3416953, 4260449, 6154217, 6154217.",
    "1785294": "Let me check that and get back to you. Thanks for pointing it out.",
    "1785295": "dschettler8845 thanks for that!",
    "1785297": "Ok, so it looks like I messed up during multiprocessing and it added an empty string **`id`** that has a few values. I'm not sure if this is an extra addition or if valuable information was overwritten. I will check this and get back. \n\nThe **`iloc`** values exhibiting this are the following\n* 154891, 1305172, 1373663, 6154217\n\nThe other numbers you mentioned look to be related to the source information being missing. I will also investigate this and get back to you.",
    "1785942": "Great dataset!",
    "1786073": "Ok, I have rerun without the parallelization and all the nan values are gone. I am updating the dataset as we speak to be correct. Thanks again for catching this!\n\n[EDIT] \n\nIt appears that while the NaN values do not exist after parsing... after saving and then loading the csv directly they appear. I am troubleshooting this now and will update it shortly with the corrected version (ETA May 12 ~2PM EST).\n\n[EDIT 2] \n\nIt appears that there were two problems:\n\n1. The newline character in some code cells is interpreted during saving and results in the creation of a new row that doesn't exist (this usually can be seen as a row with > and all nan values). **I have recreated the dataset and used a different newline interpreter to avoid this.**\n\n2. The interpretation during loading of certain strings as NaN instead of the string representation. i.e. the code block contains only the text \"null\" but pandas interpret this as pd.NaN. This can be avoided by specifying **`keep_default_na=False`** in the **`pd.read_csv()`** command (i.e. no default NaN parsing). I will update the main body of the post with information about specifying this command when loading.\n\n---\n\nI hope this clears everything up!",
    "1786136": "dschettler8845 \nwhile extracting `id` there is `dot(.)` comming with `id` Ex (`8a2564b730a575.`)\nQuickFix : \n````python\ntmp_df[\"id\"] = fpath[:-4].rsplit(\"/\", 1)[-1].strip('.')\n````\nThanks for the nice code :)",
    "1786198": "That should be fixed now. My apologies!",
    "1786214": "Thanks for the update @dschettler8845 \nI am dropping null values in my notebook. This will most probably have no effects after any updates in the dataset versions.",
    "1786562": "Hey! Nice work. Looks like we had the same idea. I ran the process on my twitch stream tonight and created a parquet version too. If people find it helpful it's here: https://www.kaggle.com/datasets/robikscube/ai4code-parquet-tabular",
    "1789514": "thank you for your work, I was gonna do it myself but I am glad I don't have to lol.",
    "1789950": "Nice work:)",
    "1790323": "Nice! I love your streams!",
    "1790324": "You're welcome! glad I could help :)",
    "1790325": "Thank you ! Glad to help!",
    "1790326": "Thank you, glad I could help!",
    "1790327": "Hahaha yes! That's the idea. :)"
  },
  "source": "meta"
}