Suppose I have this dataframe df:
column1 column2 column3
amsterdam school yeah right backtic escapes sport swimming 2016
rotterdam nope yeah 2012
thehague i now i can fly no you cannot swimming rope 2010
amsterdam sport cycling in the winter makes me 2019
How do I get the sum of all characters (exclude white-space) of each row in column2 and return it to new column4 like this:
column1 column2 column3 column4
amsterdam school yeah right backtic escapes sport swimming 2016 70
rotterdam nope yeah 2012 8
thehague i now i can fly no you cannot swimming rope 2010 65
amsterdam sport cycling in the winter makes me 2019 55
I tried this code but so far in return I got the sum of all characters of every row in column2:
df['column4'] = sum(list(map(lambda x : sum(len(y) for y in x.split()), df['column2'])))
so currently my df look like this:
column1 column2 column3 column4
amsterdam school yeah right backtic escapes sport swimming 2016 250
rotterdam nope yeah 2012 250
thehague i now i can fly no you cannot swimming rope 2010 250
amsterdam sport cycling in the winter makes me 2019 250
anybody have idea?