i am performing some operation on some datasets for recommendation with images and attributes and review.
i have an item-attribute dataset where the first column is the 'asin' of the images and the other columns are the onehot attributes.
the original test,train and val dataset have a column named 'asin' which defines the ID of the images and the other two columns.
what i want to obtain is to have the exact correspondence between the original train+test+val csv files and the other item-attribute tsv file, in order to perform correctly the operation.


the following is the code for mapping, where i map the original asin to something else. i want you to automatize the mapping with the "synchronization" of the dataset

import numpy as np
import pandas as pd
import os
import argparse

parser = argparse.ArgumentParser(description="Mapping config.")
parser.add_argument('--folder_name', type=str, help="folder name.", required=True)
args = parser.parse_args()

train = pd.read_csv('train.tsv', sep='\t', header=None)
val = pd.read_csv('val.tsv', sep='\t', header=None)
test = pd.read_csv('test.tsv', sep='\t', header=None)
attributes = pd.read_csv('item_attributes_filtered.tsv', sep='\t', header=None)

df = pd.concat([train, val, test], axis=0)

users = df[0].unique()
items = df[1].unique()

users_map = {u: idx for idx, u in enumerate(users)}
items_map = {i: idx for idx, i in enumerate(items)}

items_map_csv = pd.DataFrame(list(items_map.items()), columns=['ID', 'Value'])
items_map_csv.to_csv(f'items_map.tsv', sep='\t', index=False)

train[0] = train[0].map(users_map)
train[1] = train[1].map(items_map)

val[0] = val[0].map(users_map)
val[1] = val[1].map(items_map)

test[0] = test[0].map(users_map)
test[1] = test[1].map(items_map)

attributes[0] = attributes[0].map(items_map).astype(int)

train.to_csv('train_indexed.tsv', sep='\t', index=False, header=None)
val.to_csv('val_indexed.tsv', sep='\t', index=False, header=None)
test.to_csv('test_indexed.tsv', sep='\t', index=False, header=None)
attributes.to_csv('item_attributes_filtered_indexed.tsv', sep='\t', index=False, header=None)

# multimodal_embeddings_folder = f'{args.folder_name}'

# multimodal_embeddings_folder_indexed = f'{args.folder_name}_indexed'

# if not os.path.exists(multimodal_embeddings_folder_indexed):
#     os.makedirs(multimodal_embeddings_folder_indexed)


# for key, value in items_map.items():
#     np.save(f'{multimodal_embeddings_folder_indexed}/{value}.npy', np.load(f'{multimodal_embeddings_folder}/{key}.npy'))


these are some code operation that was made in order to go from item_attribute.tsv file to the item_attribute_filtered.tsv file to the item_attribute_filtered_indexed file.

while this code is applied to the original dataset folder of the images. 

import os
 
# Path to the folder containing the images
image_folder = 'path_to_image_folder'
 
# List of image filenames in the folder
image_filenames = set(os.listdir(image_folder))
 
# List of ASINs from the DataFrame (assuming they match image filenames without the extension)
asin_list = set(df['asin'].astype(str))  # Ensure ASINs are treated as strings
 
# Find image filenames that are not in the ASIN list (excluding file extensions)
images_to_delete = [img for img in image_filenames if os.path.splitext(img)[0] not in asin_list]
 
# Delete the images that don't have a corresponding ASIN
for img in images_to_delete:
    file_path = os.path.join(image_folder, img)
    if os.path.isfile(file_path):
        os.remove(file_path)
        print(f"Deleted {file_path}")


So, can you perform everything in the same file in the most correct possible way?