Make a new column of the first n letters of a column, where n is the value in another column
<p>I have a dataframe with names and ages:</p>

<pre><code>name:  age: 
john    2
sean    3
jack    1
peter   4 
</code></pre>

<p>Depending on their age <code>n</code> I want to print the first <code>n</code> letters of their name, so for instance <code>sean</code> becomes <code>sea</code> in a new column. </p>

<p>I have tried this:</p>

<pre><code>family['newcol'] = [x[:y] for x in family['name'] and for y in family['age']]
</code></pre>

<p>but it hasn't worked. Can anyone please give me a solution?</p>

<p>Please try this:</p>

<pre><code>family['newcol'] = [family.ix[x]['name'][0:family.ix[x]['age']] for x in family.index]
</code></pre>

python pandas