I am using Pandas and I am turning an excel spreadsheet into a dataframe and am trying to do the following:
if RowCol[2,5] is not RowCol[5,5]:
calculation
Right now my data frame is called z and I have the following:
if z.iloc[2,5] != z.iloc[5,5]:
calculation
However this does not work because it takes the value of the row,col into consideration. If row,col 2,5 is 10 and row,col 5,5 is 10 then the calculation won't run, when in fact I want it to run. The only time I don't want the calculation to run is when the row, col is 5,5.
I know that I can get the values using iloc but I don't care about the values, I just want it so that if we are not on row,col [5,5] then the calculation runs but if we hit row, col [5,5] in the dataframe then the calculation does not run but a different calculation is run only for row,col [5,5]. Does anyone know what function to use for this, I don't think I use loc?
I believe that since you are iterating over the dataframe already it would be better to just keep track of your current position. df.iterrows()
keeps track of your index.
for index, row in df.iterrows():
rownum = 1
for cell in row:
if index==5 and rownum==5:
do_stuff()
rownum+=1