so I am rewriting an excel macro, and while I have successfully recreated it; I want to redo my code because it is a bit simplistic and is more of a simpler/brute force approach to the solution. I realized I am not really utilizing pandas functionality to it's fullest extent (am new to pandas, not to python). I also didn't have the most time to develop this so I just went.
There are a solid 30 formulas I need to recreate and they are basically all if statements nested within this starting for loop (these aren't real variable names):
for row in range(len(dataframe)):
if dataframe.iat[row, 8][12:-2] == "some string":
dataframe.iat[row, 4] = "some other string"
# convert float to int into a string
elif dataframe.iat[row, 8][10:-4] == str(int(dataframe.iat[row, 13]))[2:]:
dataframe.iat[row, 4] = "some string2"
else:
dataframe.iat[row, 4] = "some string3"
Example of this code in VBA form:
=IF(MID(I2,13,2)="some string","some other string",(IF(RIGHT(N2,2)=MID(I2,11,2),"some string2","some string3")))
One more example (trust me I know using this many 'or's is not really pythonic at all - it will be fixed):
if dataframe.iat[row, 27] != 0 or dataframe.iat[row, 28] != 0 or dataframe.iat[row, 29]
!= 0 or dataframe.iat[row, 25] != 0 or dataframe.iat[row, 30] != 0:
dataframe.iat[row, 23] = "Yes"
else:
dataframe.iat[row, 23] = "No"
The biggest problem I am facing is when I have to access multiple columns and it is probably due to my lack of pandas experience.