Pandas: Calculate the number of characters in each word in a given series
Pandas: Data Series Exercise-25 with Solution
Write a Pandas program to calculate the number of characters in each word in a given series.
Sample Solution :
Python Code :
import pandas as pd series1 = pd.Series(['Php', 'Python', 'Java', 'C#']) print("Original Series:") print(series1) result = series1.map(lambda x: len(x)) print("\nNumber of characters in each word in the said series:") print(result)
Original Series: 0 Php 1 Python 2 Java 3 C# dtype: object Number of characters in each word in the said series: 0 3 1 6 2 4 3 2 dtype: int64
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program convert the first and last character of each word to upper case.
Next: Write a Pandas program to compute difference of differences between consecutive numbers of a given series.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Returns a list with n elements removed from the beginning
def tips_take(itr, n = 1): return itr[:n] print(tips_take([1, 2, 3], 5)) print(tips_take([1, 2, 3], 0))
[1, 2, 3] 
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework