import pandas as pd
import os
f1=pd.read_excel('花.xlsx',converters = {'name':int,'rename':str})
As shown below, it is f1.
Read 'flower .xlsx' file, read 'nama' in the form of an integer, read as text 'rename'.
the original name for the picture naming. rename rename a picture of the results.
filelist=os.listdir('图片')
As shown below, the read image is stored to rename folder called 'picture'.
The aim is to top six pictures, rename its nickname.
for item in filelist:
for i in range(len(f1)):
if item == str(f1.iloc[i,0])+".jpg":
os.rename('./图片/'+item,'图片/'+f1.iloc[i,1]+".jpg")
Complete code:
import pandas as pd
import os
f1=pd.read_excel('花.xlsx',converters = {'name':int,'rename':str})
filelist=os.listdir('图片')
for item in filelist:
for i in range(len(f1)):
if item == str(f1.iloc[i,0])+".jpg":
os.rename('./图片/'+item,'图片/'+f1.iloc[i,1]+".jpg")