簡體   English   中英

使用 pandas dataframe 上的名稱將圖像從一個文件夾復制到另一個文件夾

[英]Copy images from one folder to another using their names on a pandas dataframe

我有一個 pandas dataframe 包含 10000 個圖像名稱,這些圖像位於本地文件夾中。

我想過濾 dataframe 以選擇某些圖像(以 1000 秒為單位)並將這些圖像從上述本地文件夾復制到另一個本地文件夾。

有沒有辦法可以在 python 中完成?

我曾嘗試使用glob來做到這一點,但沒有多大意義。

我將在這里創建一個示例:我有以下 df:

img_name
2014.png 
2015.png 
2016.png 
2021.png 
2022.png 
2023.png  

我有一個 ex 文件夾。 “my_images”,我希望將“2015.png”和“2022.png”移動到另一個名為“proc_images”的文件夾中。

謝謝

import os
import shutil

path_to_your_files = '../my_images'
copy_to_path = '../proc_images'

files_list = sorted(os.listdir(path_to_your_files))
file_names= ["2015.png","2022.png"]

for curr_file in file_names:
    shutil.copyfile(os.path.join(path_to_your_files, curr_file),
                    os.path.join(copy_to_path, curr_file))  

像這樣的東西?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM