Frenze
Frenze

Reputation: 31

Splitting values from column into several columns

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

enter image description here

enter image description here

Thanks in advance.

Upvotes: 1

Views: 39

Answers (1)

jezrael
jezrael

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

Related Questions