根据数据框中的标签和 id 重命名图像

Rename images according to their labels and id in dataframe

我有一个 csv 文件如下:

id                                       ocr    raw_value   manual_raw_value
00219b14-37d1-42b2-95e8-65fe2a94b7a5    ABBYY   6,35        6,35
402048fd-868d-446a-8468-07a57f5386bf    ABBYY   11,68        11,68
33405269-c273-4c13-83d4-a973c42b72eb    ABBYY   VOTRE        VOTRE
9cf97fc4-d79b-4125-85d2-7dabc056caa3    ABBYY   questions.  questions.
6f63010b-2ccc-4e7a-bfe6-aab1dfc65ea3    ABBYY   nb              nb
a76d4f54-5036-4212-ab5a-921724c05910    ABBYY   tes             les
4f6c38e9-6500-4172-a472-ba8532db05d2    ABBYY   à                à

第一列是图片的id。 图像存储在名为 images 的目录中,如下所示:

00219b14-37d1-42b2-95e8-65fe2a94b7a5.png
402048fd-868d-446a-8468-07a57f5386bf.png
33405269-c273-4c13-83d4-a973c42b72eb.png
9cf97fc4-d79b-4125-85d2-7dabc056caa3.png
6f63010b-2ccc-4e7a-bfe6-aab1dfc65ea3.png
a76d4f54-5036-4212-ab5a-921724c05910.png
4f6c38e9-6500-4172-a472-ba8532db05d2.png

l 想用 manual_raw_values 重命名这些图像,这意味着 例如

00219b14-37d1-42b2-95e8-65fe2a94b7a5.png

变成

6,35.png

为此,我到目前为止所做的是:

df = pd.read_csv('/home/images/words.csv',sep=',')
df = df.astype(str)
path='/home/images/'
images_name = glob.glob("*.png")
set_img = set([x.rsplit('.', 1)[0] for x in images_name])
for img in set_img:
    label=df.loc[df.id==img, 'manual_raw_value'].item()
    # what to do next to rename the images with respect to their label and id
os.rename(img+'.png',label+'.png')