I’m trying to check if my a cell with a string value from one of my columns has a string value within from a different one of my columns. I’m using a nested for loop to parse the cell values.
for j in df["condition"]:
for i in df2["Conditions"]:
Essentially, I’ve tried converting j and i into strings, but I keep getting attribute errors. I want to use includes() on j to see if has i as a substring. Any help on converting the j and i to strings that can be used would be appreciated!
>Solution :
To convert the values of j and i to strings, you can use the str() function in Python. Here’s an example code snippet:
for j in df["condition"]:
for i in df2["Conditions"]:
if str(i) in str(j):
print("Found a match!")
In this example, str(i) and str(j) convert the values of i and j to strings, which allows you to use string methods like includes(). The if statement checks if the substring i is present in j, and if so, it prints "Found a match!".
I hope this helps! Let me know if you have any further questions.