{
  "id": 445771,
  "title": "Help to get image paths into the df. Applying lambda. Any tips?",
  "url": "/competitions/UBC-OCEAN/discussion/445771",
  "author_name": "Marília Prata",
  "post_date": "2023-10-08T18:41:30.717000",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>On this Competition the image_id are integers (on Mayo  those were string/tif file, therefore I can't apply the snippet below, with that \", x+\".png\"  at the end</p>\n<h1>Getting image paths into the df. What  should I change on that snippets?</h1>\n<p>By Saurabh (<a href=\"https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch\" target=\"_blank\">https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch</a>)<br>\ntrain_csv['image_path'] = train_csv.image_id.apply(lambda x: os.path.join(\"../input/UBC-OCEAN/train_images/\", x+\".png\"))</p>\n<p>By Junji Takeshima (<a href=\"https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng\" target=\"_blank\">https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng</a>)</p>\n<p>train_df[\"file_path\"] = train_df[\"image_id\"].apply(lambda x: \"../input/mayo-clinic-strip-ai/train/\" + x + \".tif\")</p>\n<p>I've already tried many things, including search on StackOverflow<br>\n[int(x) for x in lst]<br>\n<a href=\"https://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python\" target=\"_blank\">https://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python</a></p>\n<p>I read Jefferson's Pazze EDA on this competition. He uses that:</p>\n<p>def append_ext(fn):<br>\n    return fn+\".png\"</p>\n<p>traindf[\"image_id_path\"]=traindf[\"image_id\"].apply(append_ext)</p>\n<p>However, he got just 4.png  and I want the whole path like Junji and Saurabh delivered, like that below:<br>\n../input/UBC-OCEAN/train_images/4.png</p>\n<p>Nothing worked till now. Any tips to change that X and to get the complete image path  is welcome.</p>\n<p>In fact, I don't need it since Jirka's already run the train_images without getting path into the dataframe.  However, I'd appreciate to learn it APPLYING LAMBDA. With a simple snippet.</p>\n<p>Thanks in advance.</p>",
  "messages": [
    {
      "id": 2474576,
      "postDate": "2023-10-09T10:25:49.743Z",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/mpwolke\" target=\"_blank\">@mpwolke</a> ,</p>\n<p>Not sure if this has already been answered elsewhere. One way to get the image id path would be.</p>\n<pre><code>import pandas as pd\ntrain_df = pd()\ntrain_df = train_df(lambda x:  + (x) + )\n</code></pre>",
      "rawMarkdown": "Hi @mpwolke ,\n\nNot sure if this has already been answered elsewhere. One way to get the image id path would be.\n\n```\nimport pandas as pd\ntrain_df = pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")\ntrain_df[\"image_id_path\"] = train_df.image_id.apply(lambda x: \"/kaggle/input/UBC-OCEAN/train_images/\" + str(x) + \".png\")\n```",
      "votes": 1,
      "replies": [
        {
          "id": 2474828,
          "postDate": "2023-10-09T13:45:55.337Z",
          "content": "<p>Hi Deep, <a href=\"https://www.kaggle.com/adeep028\" target=\"_blank\">@adeep028</a> </p>\n<p>It worked Perfectly. Thank you so much for solving that issue!</p>",
          "rawMarkdown": "Hi Deep, @adeep028 \n\nIt worked Perfectly. Thank you so much for solving that issue!",
          "votes": 1
        }
      ]
    },
    {
      "id": 2473992,
      "postDate": "2023-10-08T18:41:30.717Z",
      "content": "<p>On this Competition the image_id are integers (on Mayo  those were string/tif file, therefore I can't apply the snippet below, with that \", x+\".png\"  at the end</p>\n<h1>Getting image paths into the df. What  should I change on that snippets?</h1>\n<p>By Saurabh (<a href=\"https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch\" target=\"_blank\">https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch</a>)<br>\ntrain_csv['image_path'] = train_csv.image_id.apply(lambda x: os.path.join(\"../input/UBC-OCEAN/train_images/\", x+\".png\"))</p>\n<p>By Junji Takeshima (<a href=\"https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng\" target=\"_blank\">https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng</a>)</p>\n<p>train_df[\"file_path\"] = train_df[\"image_id\"].apply(lambda x: \"../input/mayo-clinic-strip-ai/train/\" + x + \".tif\")</p>\n<p>I've already tried many things, including search on StackOverflow<br>\n[int(x) for x in lst]<br>\n<a href=\"https://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python\" target=\"_blank\">https://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python</a></p>\n<p>I read Jefferson's Pazze EDA on this competition. He uses that:</p>\n<p>def append_ext(fn):<br>\n    return fn+\".png\"</p>\n<p>traindf[\"image_id_path\"]=traindf[\"image_id\"].apply(append_ext)</p>\n<p>However, he got just 4.png  and I want the whole path like Junji and Saurabh delivered, like that below:<br>\n../input/UBC-OCEAN/train_images/4.png</p>\n<p>Nothing worked till now. Any tips to change that X and to get the complete image path  is welcome.</p>\n<p>In fact, I don't need it since Jirka's already run the train_images without getting path into the dataframe.  However, I'd appreciate to learn it APPLYING LAMBDA. With a simple snippet.</p>\n<p>Thanks in advance.</p>",
      "rawMarkdown": "On this Competition the image_id are integers (on Mayo  those were string/tif file, therefore I can't apply the snippet below, with that \", x+\".png\"  at the end\n\n# Getting image paths into the df. What  should I change on that snippets? \n\nBy Saurabh (https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch)\ntrain_csv['image_path'] = train_csv.image_id.apply(lambda x: os.path.join(\"../input/UBC-OCEAN/train_images/\", x+\".png\"))\n\nBy Junji Takeshima (https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng)\n\ntrain_df[\"file_path\"] = train_df[\"image_id\"].apply(lambda x: \"../input/mayo-clinic-strip-ai/train/\" + x + \".tif\")\n\nI've already tried many things, including search on StackOverflow\n[int(x) for x in lst]\nhttps://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python\n\nI read Jefferson's Pazze EDA on this competition. He uses that:\n\ndef append_ext(fn):\n    return fn+\".png\"\n\ntraindf[\"image_id_path\"]=traindf[\"image_id\"].apply(append_ext)\n\nHowever, he got just 4.png  and I want the whole path like Junji and Saurabh delivered, like that below:\n../input/UBC-OCEAN/train_images/4.png\n\nNothing worked till now. Any tips to change that X and to get the complete image path  is welcome.\n\nIn fact, I don't need it since Jirka's already run the train_images without getting path into the dataframe.  However, I'd appreciate to learn it APPLYING LAMBDA. With a simple snippet.\n\nThanks in advance.",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 2474576,
      "author_name": "Amar Deep",
      "author_url": "",
      "post_date": "2023-10-09T10:25:49.743000",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/mpwolke\" target=\"_blank\">@mpwolke</a> ,</p>\n<p>Not sure if this has already been answered elsewhere. One way to get the image id path would be.</p>\n<pre><code>import pandas as pd\ntrain_df = pd()\ntrain_df = train_df(lambda x:  + (x) + )\n</code></pre>",
      "votes": 1,
      "replies": [
        {
          "id": 2474828,
          "author_name": "Marília Prata",
          "author_url": "",
          "post_date": "2023-10-09T13:45:55.337000",
          "content": "<p>Hi Deep, <a href=\"https://www.kaggle.com/adeep028\" target=\"_blank\">@adeep028</a> </p>\n<p>It worked Perfectly. Thank you so much for solving that issue!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2474576": "Hi @mpwolke ,\n\nNot sure if this has already been answered elsewhere. One way to get the image id path would be.\n\n```\nimport pandas as pd\ntrain_df = pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")\ntrain_df[\"image_id_path\"] = train_df.image_id.apply(lambda x: \"/kaggle/input/UBC-OCEAN/train_images/\" + str(x) + \".png\")\n```",
    "2473992": "On this Competition the image_id are integers (on Mayo  those were string/tif file, therefore I can't apply the snippet below, with that \", x+\".png\"  at the end\n\n# Getting image paths into the df. What  should I change on that snippets? \n\nBy Saurabh (https://www.kaggle.com/code/saurabhsawhney/handling-large-images-tile-resize-and-stitch)\ntrain_csv['image_path'] = train_csv.image_id.apply(lambda x: os.path.join(\"../input/UBC-OCEAN/train_images/\", x+\".png\"))\n\nBy Junji Takeshima (https://www.kaggle.com/code/junjitakeshima/mayo-simple-cnn-starter-eng)\n\ntrain_df[\"file_path\"] = train_df[\"image_id\"].apply(lambda x: \"../input/mayo-clinic-strip-ai/train/\" + x + \".tif\")\n\nI've already tried many things, including search on StackOverflow\n[int(x) for x in lst]\nhttps://stackoverflow.com/questions/53553138/how-do-i-apply-int-to-every-string-using-map-and-lambda-in-python\n\nI read Jefferson's Pazze EDA on this competition. He uses that:\n\ndef append_ext(fn):\n    return fn+\".png\"\n\ntraindf[\"image_id_path\"]=traindf[\"image_id\"].apply(append_ext)\n\nHowever, he got just 4.png  and I want the whole path like Junji and Saurabh delivered, like that below:\n../input/UBC-OCEAN/train_images/4.png\n\nNothing worked till now. Any tips to change that X and to get the complete image path  is welcome.\n\nIn fact, I don't need it since Jirka's already run the train_images without getting path into the dataframe.  However, I'd appreciate to learn it APPLYING LAMBDA. With a simple snippet.\n\nThanks in advance."
  }
}