0

I am a newbie who is on a steep learning curve which involves transferring a long, multi-step process from Excel into python. Because I had no idea what I was doing at first, I basically just followed all the old excel macro steps in pandas, it broadly worked, and I ended up with a pandas df containing some filenames that use the cp command to create new files (based on images I already have in a folder). This is the final step of the process. The commands look like this:

cp specificimagename.jpg destinationfolder/veryspecificfilename

I had a lightbulb moment and realised that maybe, rather than going through the hassle of generating these commands in my pandas df then manually pasting them into Terminal at the end, I could just move them using Python commands as part of the script! It seems I need to use Shutil but all the examples I find on Stack Overflow are doing more complex things than I want to do. Can anyone suggest how I could do this?

Thanks!!

HB81
  • 1
  • 2
  • Would one of these answers help? https://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python `shutil.copy2(source, dest)` is a popular suggestion, and it also looks like `import os; os.system('cp specificimagename.jpg destinationfolder/veryspecificfilename')` would work. – Peter Leimbigler Oct 20 '21 at 02:38
  • thanks! that's what i'm trying to do but the filename needs to be pulled from a column in a pandas df. so for each cell in that column, i would like that filename copied to the dest folder. do you know how i would do that? – HB81 Oct 20 '21 at 10:40
  • then try using `iterrows` on the dataframe and get the filename you need then copy – Da Song Oct 20 '21 at 14:00

0 Answers0