I have a dataframe like this:
name . size . type . av_size_type
0 John . 23 . Qapra' . 22
1 Dan . 21 . nuk'neH . 12
2 Monica . 12 . kahless . 15
I want to create a new column with a sentence, like this:
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)
It would be something like this:
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)
However, apparently this sort of synthax doesn't work.
Would anyone have a suggestion for that?
return string
(and maybe get some sleep :) – Interdependent.apply(func, axis=1)
should work. – Very