Python Forum
How to sort image files according to a metadata file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to sort image files according to a metadata file?
I would like to sort image files with same tags into a specific folder.
(The HAM 10000 dataset,

A metadata file (HAM10000_metadata.csv) was made like this;

lesion_id image_id dx dx_type age sex localization
HAM_0000550 ISIC_0024306 nv follow_up 45 male trunk
HAM_0003577 ISIC_0024307 nv follow_up 50 male lower extremity
HAM_0001477 ISIC_0024308 nv follow_up 55 female trunk
HAM_0000484 ISIC_0024309 nv follow_up 40 male trunk
HAM_0003350 ISIC_0024310 mel histo 60 male chest
HAM_0000981 ISIC_0024311 nv follow_up 75 female back
HAM_0001359 ISIC_0024312 bkl histo 75 male lower extremity
HAM_0002869 ISIC_0024313 mel histo 50 female back
HAM_0002198 ISIC_0024314 nv histo 75 male lower extremity
. so on

And, all image files were named after image_id (ISIC_XXXXXXX.jpeg).
What I want is to sort these image files (ISIC_XXXXXXX.jpeg) according to the variable, "dx" (nv, mel, bkl,...) ! In a metadata file (HAM10000_metadata.csv), there are seven different values of "dx" (akiec, bcc, bk1, mel, df, vasc, nv).
Therefore, I want to put these 10,000 image files with a same value of "dx" into 7 different folders according to the metadata file which contains the macthed value of "dx" of every image file.

How can I make a script?
(all files are located at c:\ and I would like make new seven folders with same name of "dx")

Thank you for your help!!
You can use pandas.read_csv to load csv into Python memory as Pandas.DataFrame instance. Further, you can use DataFrame's groupby method. To use it you will need to specify desired grouping variables (e.g. 'dx_type' in your case). Finally, you can iterate over all groups, find which files belong to each group (from image_id column) and copy these files to specific directories.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort data from JSON file Dummy_in_programming 2 116 Jan-04-2021, 06:17 PM
Last Post: deanhystad
  Count & Sort occurrences of text in a file oradba4u 7 421 Sep-06-2020, 03:23 PM
Last Post: oradba4u
  Adding Language metadata to a PDF programmatically bhargavi22 0 314 Aug-17-2020, 12:53 PM
Last Post: bhargavi22
  METADATA Errors millpond 0 286 Jul-21-2020, 08:22 AM
Last Post: millpond
  Split and sort input file aawaleh 4 638 Apr-10-2020, 09:59 PM
Last Post: aawaleh
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 1,647 Nov-12-2019, 05:59 AM
Last Post: klllmmm
  How can I sort my names of files in for loop? Mike Ru 2 638 Aug-02-2019, 04:56 AM
Last Post: perfringo
  Parse the data in XML metadata field klllmmm 2 840 Jun-19-2019, 04:24 PM
Last Post: klllmmm
  write image into string format into text file venkat18 2 1,292 Jun-01-2019, 06:46 AM
Last Post: venkat18
  Cant seem to load my image file jamshaid1997 0 744 Jan-18-2019, 02:54 PM
Last Post: jamshaid1997

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020