I'm trying to set up a python script to take a set of data I've assembled to automate the movement of files from a source location to several other folders based on an if/then statement.
Ideally, the code would 1.) read the dataframe and check to see if two of the columns match a set text input 2.) iterate through each of the rows in the dataframe to determine which rows satisfy the these criteria 3.) read the text in first column of the correct rows and concatenate the file location for the source file to be transferred to.
Here is what I currently have:
import pandas as pd
import numpy as np
import shutil
df = pd.read_excel(r'\\KCOW00\Jobs\72046\Design\Bridges\Statewide Bridge Data\z_Scratch\CCD\Python Tests\data.xlsx')
src = r'\\KCOW00\Jobs\72046\Design\Bridges\Statewide Bridge Data'
yr8 = r'\2022_Year 8'
auto = r'\Field Investigation Reference\Automation'
culv = r'\KLBRP - CBWOP Field Sketch Forms - Culvert.pdf'
grdr = r'\KLBRP - CBWOP Field Sketch Forms - Girder Bridge.pdf'
slab = r'\KLBRP - CBWOP Field Sketch Forms - Slab Bridge.pdf'
br_num = df['NBI Bridge Number']
district = df['District']
county = df['County']
owner = df['Owner Group']
type = df['Type']
br_type = df['BR_Type']
span = df['Span']
def Add_Forms:
if (type == 'CBWOP') & (br_type == '19-Culvert'):
shutil.copy2(src + auto + culv, src + yr8 + '\\' + district + '\\' + county + '\\' + owner + '\\' + br_num + '\\' + 'Field Investigation' + culv)
elif (type == 'CBWOP') & (br_type == '01-Slab'):
shutil.copy2(src + auto + slab, src + yr8 + '\\' + district + '\\' + county + '\\' + owner + '\\' + br_num + '\\' + 'Field Investigation' + slab)
elif (type == 'CBWOP') & (br_type == '02-Stringer/Girder'):
shutil.copy2(src + auto + grdr, src + yr8 + '\\' + district + '\\' + county + '\\' + owner + '\\' + br_num + '\\' + 'Field Investigation' + grdr)
Add_Forms
I'm currently receiving a ValueError because the truth value is ambiguous. Thanks for the help.