Python Pandas Memory Error during Drop
<p>I have a df of 825468 rows.
I am performing this over it.</p>

<pre><code>  frame = frame.drop(frame.loc[(
            frame['RR'].str.contains(r"^([23])[^-]*-\1[^-]*$")), 'RR'].str.replace("[23]([^-]*)-[23]([^-]*)", r"\1-\2").isin(
             series1.str.replace("1([^-]*)-1([^-]*)", r"\1-\2"))[lambda d: d].index)
</code></pre>

<p>where </p>

<pre><code>  series1 = frame.loc[frame['RR'].str.contains("^1[^-]*-1"), 'RR']
</code></pre>

<p>So what it does it</p>

<p>prepares a series of where <code>RR</code> has value like <code>1abc-1bcd</code> and then if in frame there is an <code>RR</code> like <code>2abc-2bcd</code> which after replacement becomes <code>abc-bcd</code> and its there in series as well after replacement,its dropped.</p>

<p>But it gives Memory Error.Is there a more efficient way to perform the same.</p>

<p>For ex.</p>

<p>if in a df ..</p>

<pre><code>     RR
0    2abc-2abc
1    1abc-1abc
2    3abc-3abc
3    2def-2def
4    3def-3def
5    def-dfd
6    sdsd-sdsd
7    1def-1def
</code></pre>

<p>Then from this frame <code>2abc-2abc</code> and <code>3abc-3abc</code> should be dropped,as after removing 2,3 it becomes <code>abc-abc</code> and when we remove <code>1</code> from <code>1abc-1abc</code> it also is <code>abc-abc</code>.<code>2def-2def</code> should not be dropped as there is no <code>1def-1def</code></p>

<p>Output:</p>

<pre><code>     RR
0    1abc-1abc
1    def-dfd
2    sdsd-sdsd
3    1def-1def
</code></pre>