2016-08-29 23 views
1

我有姓名和年龄一个数据框的值的第N个字母的新列:使列,其中n是另一列

name: age: 
john 2 
sean 3 
jack 1 
peter 4 

根据他们的n年龄上我要打印第一个n他们名字的字母,因此例如sean在新列中变成sea

我已经试过这样:

family['newcol'] = [x[:y] for x in family['name'] and for y in family['age']] 

,但并未奏效。任何人都可以请给我一个解决方案?

回答

2

请试试这个:

family['newcol'] = [family.ix[x]['name'][0:family.ix[x]['age']] for x in family.index] 
相关问题