这是使用 Pandas 的一种方法:# Create example data framedf = pd.DataFrame([('../dir_a/1.png', 5.14), ('../dir_a/2.png', 5.15), ('../dir_b/3.png', 4.19), ('../dir_b/4.png', 3.81)], columns = ['path', 'score'])# Split the file path by '/' and expand into columns with original data framedf = pd.concat([df.path.str.split('/', expand=True), df], axis=1)# Group the rows based on the directory name (column 1) and find the max scoredf.groupby(1)['score'].max().reset_index() 1 score0 dir_a 5.151 dir_b 4.19然后,如果需要,您可以将这些值转换回列表。