How to create a DataFrame series as a sub-string of a DataFrame Index?
<p>I have a Pandas DataFrame which has a 5-digit string as its index (the index is a 5 digit zip code). I'd need to create another series in the DataFrame which is the first three characters of the index (i.e. the 3-Digit zip code).</p>

<p>As an example, if the index for a row is "32779", I'd like the new series' value to be "327".</p>

<p>I thought a Lambda function may work e.g.</p>

<pre><code>fte5['Zip3'] = fte5.index.astype(str).apply(lambda x: x[:3])
</code></pre>

<p>But this gives an error</p>

<p>This worked:</p>

<pre><code>fte5['Zip3'] = fte5.index.get_level_values(0)
fte5['Zip3'] = fte5['Zip3'].astype(str).apply(lambda x: x[:3]) 
</code></pre>

python pandas dataframe