Reputation: 31
I have a pandas dataframe that I want the numbers of the column C to be added together and created a new column D.
For example
Thanks in advance.
Upvotes: 1
Views: 39
Reputation: 862511
Use Series.str.extractall
for get numbers separately, convert to integers and last sum per first level of MultiIndex
:
df['D'] = df['C'].str.extractall('(\d)').astype(int).sum(level=0)
Upvotes: 3