I am trying to compare values in 2 columns of a dataframe from the input and check for equality:
My input is a list like:
ABC BCD
QWE XYZ
MNO PQR
My dataframe looks like:
St1 St2
ABC BCD
PQR XYZ
MNO PQR
I want to check of the input is present in my dataframe. And if yes, then corresponding to each of the values, I append a "Yes" or "No" on the basis of whether it is present or not.
I am trying to do this:
for i in range(len(pairs)):
if df_final['Stock1']==pairs[i][0]:
df["corr"] = "Yes"
This doesnt work and give the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
How can it be rectified?
I have tried this as well:
k = pairs[0]
df[(df[['St1','St2']].values == k).all(axis=1)]
where pairs is the input
df_final. Can you paste a sample of that?