frutiemax commited on
Commit
a368945
1 Parent(s): 9f82930

Add script to append rows not present in existing metadata.csv

Browse files
Files changed (1) hide show
  1. create_json.py +15 -2
create_json.py CHANGED
@@ -18,7 +18,7 @@ for folder in folders:
18
  view = 0
19
  for image in images:
20
  object_description = folder.replace('_', ' ')
21
- entry = {'file_name' : image, 'object_type' : 'small_scenery', 'object_description' : object_description, 'view': view, 'color1' : 'none', 'color2' : 'none', 'color3' : 'none'}
22
  entries.append(entry)
23
  view = view + 1
24
 
@@ -28,4 +28,17 @@ dataframe = pandas.DataFrame(entries)
28
  # dont overwrite the old metadata.csv
29
  if os.path.exists('metadata.csv'):
30
  shutil.copyfile('metadata.csv', 'metadata_backup.csv')
31
- dataframe.to_csv('metadata.csv')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  view = 0
19
  for image in images:
20
  object_description = folder.replace('_', ' ')
21
+ entry = {'file_name' : folder + '/' + image, 'object_type' : 'small_scenery', 'object_description' : object_description, 'view': view, 'color1' : 'none', 'color2' : 'none', 'color3' : 'none'}
22
  entries.append(entry)
23
  view = view + 1
24
 
 
28
  # dont overwrite the old metadata.csv
29
  if os.path.exists('metadata.csv'):
30
  shutil.copyfile('metadata.csv', 'metadata_backup.csv')
31
+
32
+ # read the existing metadata.csv and add only the rows that do not exist
33
+ output_dataframe = pandas.read_csv('metadata.csv')
34
+
35
+ # drop the rows where the object description exists
36
+ obj_descs = output_dataframe['object_description']
37
+ for obj_desc in obj_descs:
38
+ dataframe = dataframe.drop(dataframe[dataframe['object_description'] == obj_desc].index)
39
+
40
+ output_dataframe = pandas.concat([output_dataframe, dataframe]).drop_duplicates().reset_index(drop=True)
41
+ output_dataframe.to_csv('metadata.csv')
42
+
43
+ else:
44
+ dataframe.to_csv('metadata.csv')