+ 8
When you use the square bracket notation to access values in a Pandas DataFrame, it returns a Series. This means that you are trying to evaluate the truth value of a Series, which is not allowed in Python. To avoid this error, you can use the loc or iloc method to access the individual cells in your DataFrame. The loc method allows you to access values by the label of the row and column, while the iloc method allows you to access values by their numerical index. Here's an example of how you could rewrite your code using the loc method: for x in df.index: if df.loc[x, "seconds_diff"] >= 30 and not df.loc[x, "qty_match"]: # Do something Or, using the iloc method: for x in df.index: if df.iloc[x, df.columns.get_loc("seconds_diff")] >= 30 and not df.iloc[x, df.columns.get_loc("qty_match")]: # Do something can also use the .at method to access individual cells in your DataFrame, which is similar to the loc method but optimized for accessing single values. However, since you are proces
10th Dec 2022, 8:20 AM
Sadaam Linux
Sadaam Linux - avatar
+ 6
since you are processing the DataFrame row by row, using loc or iloc might be more efficient.
10th Dec 2022, 9:18 AM
Sadaam Linux
Sadaam Linux - avatar
+ 3
Check this post. https://stackoverflow.com/questions/21415661/logical-operators-for-boolean-indexing-in-pandas You are trying to apply logical operators on numpy arrays. I think you may need to use & symbol instead of "and" operator, and maybe also apply some parentheses, but without testing with your data I cannot confirm for sure.
10th Dec 2022, 8:00 AM
Tibor Santa
Tibor Santa - avatar