Issue
so I have a dataframe with a column "dname".
It contains many rows of 2LD domain names. i.e. [123ask , example92 , what3ver]
.
I want to find the number of digits for every string in every row.
So, to create a new column in the dataframe with values i.e. [3 , 2 , 1]
.
I have:
df['numeric']= sum (x.isdigit() for b in df['dname'] for x in b)
And all i get is 6 6 6
instead of 3 2 1
Any help ? Thanks in advance!
Solution
You almost had it.
df = {'dname':["123ask", "example92" , "what3ver"]}
df['numeric'] = [sum (x.isdigit() for x in b) for b in df['dname']]
print(df['numeric'])
#>>> [3, 2, 1]
print(sum(df['numeric']))
#>>> 6
Answered By - Sebastian Wozny
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.