I was working with a dataset that had mostly textual columns one of which contained words and I wanted to find the character count for each word so that I can analyze the average characters of that column. I came up with a solution that uses list comprehension and the len() function but I was looking for more methods of doing the same thing, if there are more methods please do provide them below using an example code. Here is the code I used:
You can use the same series of words I have used in your example codes if you are providing any.
Hey @mubashir_rizvi , you can use “str.count()” method to achieve desired result. In Python, str.count() is a string method that returns the number of occurrences of a substring in the given string. The pattern provided to the function is "\w" which is a regular expression pattern that matches alphanumeric characters and in this way, we consider both letters and digits in the count.
Hey @mubashir_rizvi , you can achieve this task by using str.len() method.The str.len() is a string method that returns the length of a string i.e., the number of characters in it and it can be directly applied to a series object. Let me show you a example: