How to find the count of spaces in a dataframe using python
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Island
--
Chapters
00:00 Question
00:41 Accepted answer (Score 3)
01:01 Thank you
--
Full question
https://stackoverflow.com/questions/6937...
Accepted answer links:
[Series.str.count]: http://pandas.pydata.org/pandas-docs/sta...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Island
--
Chapters
00:00 Question
00:41 Accepted answer (Score 3)
01:01 Thank you
--
Full question
https://stackoverflow.com/questions/6937...
Accepted answer links:
[Series.str.count]: http://pandas.pydata.org/pandas-docs/sta...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
ACCEPTED ANSWER
Score 3
Use Series.str.count with \s+ for match spaces:
df['count'] =df['Key'].str.count('\s+')
print (df)
Key count
0 Identifier 0
1 Identifier Number 1
2 user identifier number 2
3 user 0
4 Location of user 2