Python Practice › Pandas Programs › Program 26
Length of each word
Write a pandas program to count the characters of each word.
Input
["Virat", "Rohit", "Pant", "Shikhar"]
Output
0 5 1 5 2 4 3 7 dtype: int64
Approach
str.len().
Solution
import pandas as pdprint(pd.Series(["Virat", "Rohit", "Pant", "Shikhar"]).str.len())Output
0 5 1 5 2 4 3 7 dtype: int64
Note
“Virat” and “Rohit” have 5 letters; the original sample showed 6.
Learn the concept
New to this topic? Read the lesson, then come back.