I currently have the following conditional:
if not tops_subset.eq(row.iloc[2:4]).all(axis=1).any():For some background, it is from this code block:
tops_df = pd.read_csv('tops.csv', header=None)tops_subset = tops_df.iloc[:, 2:4]rows_written = 0with open('for_email.csv', 'w', newline='') as for_email_file: for index, row in df_sorted_no_duplicates.iterrows(): # Check if the third and fourth columns of the current row exist in 'tops.csv' if not tops_subset.eq(row.iloc[2:4]).all(axis=1).any():It correctly checks if data in two columns already exist in any row of the file tops.csv
I want to modify if so that it accommodates a second condition. The second condition is that tops_subset.eq(row.iloc[2:4]).all(axis=1).any() is true AND the value in the second from last column in the row in tops.csv where the data exist is 0.
To be clear, I want the if statement to accept either:
- The one it is already accepting which has the
notstatement
OR
- The condition I described above
I am having trouble checking if the row where the data exists has a 0 in the second from last column. This is where I need help.
I have tried this:
if (tops_subset.eq(row.iloc[2:4]).all(axis=1).any() and tops_subset.iloc[:, -2].eq(0).any()) or not tops_subset.eq(row.iloc[2:4]).all(axis=1).any():and this:
if (tops_subset.eq(row.iloc[2:4]).all(axis=1).any() and tops_subset.loc[tops_subset.eq(row.iloc[2:4]).all(axis=1), int(tops_subset.columns[-2])].eq(0).any()) or not tops_subset.eq(row.iloc[2:4]).all(axis=1).any():Both don't work.