AnswerBun.com

Count percentage of upper case words

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.

One Answer

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

Add your own answers!

Related Questions

Is clang-11’s invocation of headers via -fcoroutines flag?

0  Asked on January 18, 2021 by jerry-ajay

       

Operational Error connecting to SQL Server through Python3.7

1  Asked on January 18, 2021 by christopher-ell

     

Logo is not changing

1  Asked on January 18, 2021 by paul-ocarde

 

Android rdate exception

0  Asked on January 18, 2021 by elior-cohen

 

list assignment index out of range in a list array

3  Asked on January 18, 2021 by marc833

 

std::transform over QMap

1  Asked on January 18, 2021 by vencat

     

Loop inside the function that accepts the parameter

1  Asked on January 18, 2021 by abi-wardani

     

RegEx Print a Custom Line

1  Asked on January 18, 2021 by user9938830

   

What is localhost 3000?

3  Asked on January 18, 2021 by dawit-mesfin

   

a (recursive) function that will calculate sum for a given n

2  Asked on January 17, 2021 by randomobject123

     

C – can’t prepend a linked list

2  Asked on January 17, 2021 by ilmoi

     

R: count distinct IDs where selected column is non-null

4  Asked on January 17, 2021 by austin-gilbert

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir