Stack Overflow Asked by user13623188 on November 28, 2020
I would like to determine the percentage of upper case words in texts
Sent
Include DETAILS about YOUR goal
Describe expected and actual results
Include any ERROR messages
The below code should be able to determine the percentage of upper case (I think), but not for words but character (and in a string):
alph = list(filter(str.isalpha, s))
sum(map(str.isupper, alph)) / len(alph)
For looking at the upper case words in each row, I tried as follows:
df['UP'] = df['Sent'].str.findall(r'b([A-Z]{2,})')
and this should work. However I do not know how to calculate the percentage. I hope you can give me some tips on how to calculate it. I think I would count the number of words in each row but I do not know how to do it.
Let us try
df['UP'] = df['Sent'].str.findall(r'[A-Z]').str.len()
Or we do count
df['Sent'].str.count(r'[A-Z]')
Correct answer by BEN_YO on November 28, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP