Here is what we start with.
In : df1
0 ram 1873
1 rob 1900
In : df2
0 ram A good kid
1 ram He was born on 1873
2 rob He is tall
3 rob He is 12 yrs old
4 rob His father died at 1900
What you probably want to do is merge your two DataFrames. If you're familiar with SQL, this is just like a table join. The
pd.merge step essentially "adds" the columns from
df2 by checking where the two DataFrames match on the column "name". Then, once you have the columns you want ("year" and "text") matching according to the "name" column, we apply the function
lambda x: str(x.year) in x.text (which checks if the year is present in the text) across the rows (
In : cond = pd.merge(
...: ).apply(lambda x: str(x.year) in x.text, axis=1)
This gives us a Series which has the same index as your second DataFrame, and contains boolean values telling you if your desired condition is met or not.
In : cond
Then, we filter your Series to where the condition is true, and give the index, optionally converting it to a list.
In : cond[cond].index
Out: Int64Index([1, 4], dtype='int64')
In : cond[cond].index.tolist()
Out: [1, 4]
If all you need later on is to iterate over the indices you've gotten,
In  and
In  will suffice.