Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check if iterator is within another iterator?

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading