简体   繁体   English

使用 pandas dataframe 上的名称将图像从一个文件夹复制到另一个文件夹

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

I have a pandas dataframe that consists of 10000s of image names and these images are in a folder locally.我有一个 pandas dataframe 包含 10000 个图像名称,这些图像位于本地文件夹中。

I want to filter that dataframe to pick certain images (in 1000s) and copy those images from the aformentioned local folder to another local folder.我想过滤 dataframe 以选择某些图像(以 1000 秒为单位)并将这些图像从上述本地文件夹复制到另一个本地文件夹。

Is there a way that it can be done in python?有没有办法可以在 python 中完成?

I have tried to do that using glob but couldn't make much sense out of it.我曾尝试使用glob来做到这一点,但没有多大意义。

I will create an sample example here: I have the following df:我将在这里创建一个示例:我有以下 df:

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

I have a folder for ex.我有一个 ex 文件夹。 "my_images" and I wish to move "2015.png" and "2022.png" to another folder called "proc_images". “my_images”,我希望将“2015.png”和“2022.png”移动到另一个名为“proc_images”的文件夹中。

Thanks谢谢

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))  

Something like this?像这样的东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas 将列名从一个数据帧复制到另一个 - Pandas copy column names from one dataframe to another 如何使用 Python 将图像从一个文件夹复制到另一个文件夹? - How to copy images from one folder to another using Python? 使用 Pandas 将列从一个 DataFrame 复制到另一个 DataFrame 的最快方法? - Fastest way to copy columns from one DataFrame to another using pandas? 将文件从一个文件夹复制到另一个在 .txt 文件中具有匹配名称的文件夹 - Copy files from one folder to another with matching names in .txt file 如何在python中将备用图像从一个文件夹复制到另一个文件夹 - How to copy alternate images from one folder to another in python 仅将两列从一个DataFrame复制到Pandas中的另一列 - Copy just two columns from one DataFrame to another in pandas 根据 Pandas 中的列值将内容从一个 Dataframe 复制到另一个 Dataframe - Copy contents from one Dataframe to another based on column values in Pandas 根据 Pandas 中的 id 将列值从一个数据帧复制到另一个数据帧 - Copy column value from one dataframe to another based on id in Pandas 尝试对2个pandas数据框进行排序,然后从一个复制到另一个 - Trying to sort 2 pandas dataframe and then copy from one to another 使用 .to_numpy() 将特定列从 Pandas Dataframe 的一行复制到另一行 - Using .to_numpy() to copy specific columns from one row of Pandas Dataframe to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM