{
  "id": 272278,
  "title": "Data is not appending to DF",
  "url": "/competitions/rsna-miccai-brain-tumor-radiogenomic-classification/discussion/272278",
  "author_name": "",
  "post_date": "2021-09-14T19:18:34.088587300Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<pre><code>classes = [\"FLAIR\",\"T1w\",\"T1wCE\",\"T2w\"]\nd = []\n\nfor c in classes:\n    for index, data in test_data.iterrows():\n        img_count = len(os.listdir(os.path.join(data[\"im_path\"],c)))\n        data[c] = img_count\n        print(data[c], data['im_folder'])\n\n        new = {'type': c,\n              'img_count': img_count,\n              'id': data['im_folder']}\n\n        d.append(new)\n</code></pre>\n<p>I'm trying to do count the files in related folders and write to DF's column. The code is adding information to the dictionary with no error, but not adding to DF. What is my mistake here?</p>",
  "messages": [
    {
      "id": "1513080",
      "postDate": "09/14/2021 19:18:34",
      "content": "<pre><code>classes = [\"FLAIR\",\"T1w\",\"T1wCE\",\"T2w\"]\nd = []\n\nfor c in classes:\n    for index, data in test_data.iterrows():\n        img_count = len(os.listdir(os.path.join(data[\"im_path\"],c)))\n        data[c] = img_count\n        print(data[c], data['im_folder'])\n\n        new = {'type': c,\n              'img_count': img_count,\n              'id': data['im_folder']}\n\n        d.append(new)\n</code></pre>\n<p>I'm trying to do count the files in related folders and write to DF's column. The code is adding information to the dictionary with no error, but not adding to DF. What is my mistake here?</p>",
      "rawMarkdown": "```\nclasses = [\"FLAIR\",\"T1w\",\"T1wCE\",\"T2w\"]\nd = []\n\nfor c in classes:\n    for index, data in test_data.iterrows():\n        img_count = len(os.listdir(os.path.join(data[\"im_path\"],c)))\n        data[c] = img_count\n        print(data[c], data['im_folder'])\n\n        new = {'type': c,\n              'img_count': img_count,\n              'id': data['im_folder']}\n\n        d.append(new)\n```\nI'm trying to do count the files in related folders and write to DF's column. The code is adding information to the dictionary with no error, but not adding to DF. What is my mistake here?",
      "votes": null
    },
    {
      "id": "1513812",
      "postDate": "09/15/2021 12:40:57",
      "content": "<p>I don’t know, it’s so hard to tell by looking at a part of the code and not seeing what kind of error occurs. try creating a frame from lists.<br>\na = []<br>\nb = []<br>\na.append (img_id)<br>\nb.append (folder)<br>\ndf = pd.DataFrame.from_dict ({'a': a, 'b': b})</p>",
      "rawMarkdown": "I don’t know, it’s so hard to tell by looking at a part of the code and not seeing what kind of error occurs. try creating a frame from lists.\na = []\nb = []\na.append (img_id)\nb.append (folder)\ndf = pd.DataFrame.from_dict ({'a': a, 'b': b})",
      "votes": null
    },
    {
      "id": "1514517",
      "postDate": "09/16/2021 06:42:36",
      "content": "<p>Did you adept the code for your post here? If <code>d</code> in your original code is a DataFrame, the append won't be inplace, i.e. you have to write <code>d = d.append(new)</code>.<br>\nAlternatively create the DataFrame from a list of dicts.</p>\n<p>See <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html\" target=\"_blank\">https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html</a></p>",
      "rawMarkdown": "Did you adept the code for your post here? If `d` in your original code is a DataFrame, the append won't be inplace, i.e. you have to write `d = d.append(new)`.\nAlternatively create the DataFrame from a list of dicts.\n\nSee https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html",
      "votes": null
    },
    {
      "id": "1514844",
      "postDate": "09/16/2021 13:20:26",
      "content": "<p>d is just a temporary list of dictionaries. Data is adding to d but not adding to DF</p>",
      "rawMarkdown": "d is just a temporary list of dictionaries. Data is adding to d but not adding to DF",
      "votes": null
    },
    {
      "id": "1515443",
      "postDate": "09/17/2021 05:52:52",
      "content": "<p>Thank you soo much. I decided to do visualization on the dictionary that I created without adding to my df.</p>",
      "rawMarkdown": "Thank you soo much. I decided to do visualization on the dictionary that I created without adding to my df.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1513812,
      "author_name": "zaakciiru",
      "author_url": "",
      "post_date": "09/15/2021 12:40:57",
      "content": "<p>I don’t know, it’s so hard to tell by looking at a part of the code and not seeing what kind of error occurs. try creating a frame from lists.<br>\na = []<br>\nb = []<br>\na.append (img_id)<br>\nb.append (folder)<br>\ndf = pd.DataFrame.from_dict ({'a': a, 'b': b})</p>",
      "votes": null,
      "replies": [
        {
          "id": 1515443,
          "author_name": "berkayuyar",
          "author_url": "",
          "post_date": "09/17/2021 05:52:52",
          "content": "<p>Thank you soo much. I decided to do visualization on the dictionary that I created without adding to my df.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1514517,
      "author_name": "agrica",
      "author_url": "",
      "post_date": "09/16/2021 06:42:36",
      "content": "<p>Did you adept the code for your post here? If <code>d</code> in your original code is a DataFrame, the append won't be inplace, i.e. you have to write <code>d = d.append(new)</code>.<br>\nAlternatively create the DataFrame from a list of dicts.</p>\n<p>See <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html\" target=\"_blank\">https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1514844,
          "author_name": "berkayuyar",
          "author_url": "",
          "post_date": "09/16/2021 13:20:26",
          "content": "<p>d is just a temporary list of dictionaries. Data is adding to d but not adding to DF</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1513080": "```\nclasses = [\"FLAIR\",\"T1w\",\"T1wCE\",\"T2w\"]\nd = []\n\nfor c in classes:\n    for index, data in test_data.iterrows():\n        img_count = len(os.listdir(os.path.join(data[\"im_path\"],c)))\n        data[c] = img_count\n        print(data[c], data['im_folder'])\n\n        new = {'type': c,\n              'img_count': img_count,\n              'id': data['im_folder']}\n\n        d.append(new)\n```\nI'm trying to do count the files in related folders and write to DF's column. The code is adding information to the dictionary with no error, but not adding to DF. What is my mistake here?",
    "1513812": "I don’t know, it’s so hard to tell by looking at a part of the code and not seeing what kind of error occurs. try creating a frame from lists.\na = []\nb = []\na.append (img_id)\nb.append (folder)\ndf = pd.DataFrame.from_dict ({'a': a, 'b': b})",
    "1514517": "Did you adept the code for your post here? If `d` in your original code is a DataFrame, the append won't be inplace, i.e. you have to write `d = d.append(new)`.\nAlternatively create the DataFrame from a list of dicts.\n\nSee https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html",
    "1514844": "d is just a temporary list of dictionaries. Data is adding to d but not adding to DF",
    "1515443": "Thank you soo much. I decided to do visualization on the dictionary that I created without adding to my df."
  },
  "source": "meta"
}