我有一个这样的数据框:
name . size . type . av_size_type
0 John . 23 . Qapra' . 22
1 Dan . 21 . nuk'neH . 12
2 Monica . 12 . kahless . 15
我想用一个句子创建一个新列,如下所示:
name . size . type . av_size_type . sentence
0 John . 23 . Qapra' . 22 . "John has size 23, above the average of Qapra' type (22)"
1 Dan . 21 . nuk'neH . 12 . "Dan has size 21, above the average of nuk'neH type (21)"
2 Monica . 12 . kahless . 15 . "Monica has size 12l, above the average of kahless type (12)
它会是这样的:
def func(x):
string="{0} has size {1}, above the average of {2} type ({3})".format(x[0],x[1],x[2],x[3])
return string
df['sentence']=df[['name','size','type','av_size_type']].apply(func)
但是,显然这种合成器不起作用。
有人对此有什么建议吗?