this my data frame my dataframe i use this code to get something called WT
DF['T.U']=DF['WIDE']*DF['LENGTH']*DF['QTY']/1000000 DF['CLAD_THK']*DF['LENGTH']*DF['QTY']/1000000
DF['U.W']=DF['THK']*78.5/10 DF['CLAD_THK']*79.9/10
DF['W.T']=DF['T.U']*DF['U.W']
DF['W.T']=DF['WT']/1000
this is how data is after applying code data frame after code I want to add conditions depending on the MAT column to calculate WT for example if i have MAT=516, apply this code
DF['T.U']=DF['WIDE']*DF['LENGTH']*DF['QTY']/1000000 DF['CLAD_THK']*DF['LENGTH']*DF['QTY']/1000000
DF['U.W']=DF['THK']*78.5/10 DF['CLAD_THK']*79.9/10
DF['W.T']=DF['T.U']*DF['U.W']
DF['W.T']=DF['WT']/1000
if MAT=240 apply this
DF['T.U']=DF['WIDE']*DF['LENGTH']*DF['QTY']/1000000 DF['CLAD_THK']*DF['LENGTH']*DF['QTY']/1000000
DF['U.W']=DF['THK']*79.9/10 DF['CLAD_THK']*79.9/10
DF['W.T']=DF['T.U']*DF['U.W']
DF['W.T']=DF['WT']/1000
CodePudding user response:
You should iterate over rows on your dataframe:
for index, row in DF.iterows():
if (row['MAT'] == 516):
# Apply code 1 on row instead of DF
elif (row['MAT'] == 240):
# Apply code 2 on row instead of DF