Delete first n digits from a column
<p>I have a pandas dataframe(roughly 7000 rows) that looks as follows:</p>

<pre><code>Col1    Col2
12345   1234
678910  6789 
</code></pre>

<p>I would like to delete the first 4 digits from col1, so as to end up with:</p>

<pre><code>Col1   Col2
5      1234
10     6789
</code></pre>

<p>Or just separate the first column in 2 columns.</p>

<p>Separating first column into two new ones:</p>

<pre><code>In [5]: df[['New1','New2']] = (df['Col1'].astype(str)
                                         .str.extract(r'(\d{4})(\d+)', expand=True)
                                         .astype(int))

In [6]: df
Out[6]:
     Col1  Col2  New1 New2
0   12345  1234  1234    5
1  678910  6789  6789   10

In [9]: df.dtypes
Out[9]:
Col1    int64
Col2    int64
New1    int32
New2    int32
dtype: object
</code></pre>

<p><strong>NOTE:</strong> this solution will work with Pandas version 0.18.0+</p>

python database pandas dataframe