I am trying to match a substring in a column in my dataframe but I am unable to find it. Although the substring is present in the column. I tried for other columns and it is working perfectly. The substring can be seen in the column clearly but still it says not found
fullstring = df.Notes
substring = "Beyond Basics: Develop Your Skills"
if substring in fullstring:
print("Found!")
else:
print("Not found!")
CodePudding user response:
try verifying the Spaces before and after the substring in the df.Notes.
CodePudding user response:
The code you have written only matches with the full string. So it is looking for each record in the column, and checking if the substring variable is equal to any of it.
To do this you can do:
df.Notes.str.contains(substring)
This will give you an array with True/False values.
If you want to return the rows which contains this substring then you can do this
df[df.Notes.str.contains(substring)]