Pandas Data Frame - Merge Two Data Frames based on "InStr" > 0
<p>I have two DataFrames in Python Pandas.</p>

<p>Data stored in the cells are as follows:</p>

<pre><code>DF1
- DatabaseId    Integer
- DatabaseName  String

DF2
- CreateString  String
</code></pre>

<p>I want to apply the column DataBaseID to any record in DF2 where the DF1.DatabaseName exists within the context of Create String.</p>

<pre><code>Example:
DatabaseName = "UserDB"        CreateString = "This create string would fail"
DatabaseName = "UserDB"        CreateString = "This create string has UserDB in it"
</code></pre>

<p>The first record would fail and not be included in the resulting set.
The second record would succeed and would be in the resulting set.</p>

<p>I've researched a variety of options including <code>.isin</code>, and <code>.contains</code>, but these have not worked.  This seems to be a 'controlled' Cartesian join with an 'if match found success' condition.  But I haven't been able to find a way to do this, and it efficiently.</p>

<p>Total list size needing to be evaluated are between 100K and 500K each.</p>

<p><strong><em>UPDATE</em></strong>
Added More Example Data:</p>

<pre><code>&gt;&gt;&gt; DF1.head(10)
DatabaseID     DatabaseName
0              DB1
1              DB2
2              DB3
3              DB4
...

&gt;&gt;&gt; DF2.head(10)
CreateString
None
None
None
CREATE VIEW DB1.Table1 AS LOC…
None
REPLACE VIEW DB3.Table3...
CREATE VIEW DB3.Table10 AS SELE...
CREATE VIEW DB55.Table999 AS SELEC...
...

Desired Result
DatabaseID      DatabaseName        CreateText
0               DB1                 CREATE VIEW DB1.Table1 AS LOC…
2               DB3                 REPLACE VIEW DB3.Table3...
2               DB3                 CREATE VIEW DB3.Table10 AS SELE...
...
etc...
...
</code></pre>