How to compute number of characters in each word in pandas series

In Python, the pandas library includes built-in functionalities that allow you to perform different tasks with only a few lines of code. One of these functionalities is computing the number of characters in each word.

Method

In this method, we first initialize a pandas series. We then iterate over each entry and compute the length of each entry of the series. Then, we map the lengths with each respective entry in the series.

#importing pandas library
import pandas as pd
#initializing pandas series
series = pd.Series(['educative', 'io', 'edpresso'])
#computing number of characters in series
result = series.map(lambda iterator: len(iterator))
print(result)

The left column is the word index (i.e., which word of the three it is) and the right column is the number of letters in that word.

Free Resources