I have a dataframe with 2 columns containing floats. I first excluded rows where columns contain zeros and then wanted to check for each row, if the elements of the columns are equal.
I tried:
df.loc[(df['col1'] != 0.0) & (df['col2'] != 0.0), 'Error'] = np.where(assert_almost_equal(df['col1'], df['col2']), 'Not equal', '')
result was:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
and also tried:
np.where(df['col1'] == df['col2'], 'Not equal', '')
and
np.where(df.col1.eq(df.col2), 'Not equal', '')
and result was:
ValueError: shape mismatch: value array of shape (24788,) could not be broadcast to indexing result of shape (9576,)
and also tried apply
-function.
How can I compare the floats within two columns row by row? I do really want need equality, not isclose
or something similar.
Thank you,
MaMo