Q:

Write a Pandas program to filter words from a given series that contain atleast two vowels

0

Write a Pandas program to filter words from a given series that contain atleast two vowels.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
from collections import Counter
color_series = pd.Series(['Red', 'Green', 'Orange', 'Pink', 'Yellow', 'White'])
print("Original Series:")
print(color_series)
print("\nFiltered words:")
result = mask = color_series.map(lambda c: sum([Counter(c.lower()).get(i, 0) for i in list('aeiou')]) >= 2)
print(color_series[result])

Sample Output:

Original Series:
0       Red
1     Green
2    Orange
3      Pink
4    Yellow
5     White
dtype: object

Filtered words:
1     Green
2    Orange
4    Yellow
5     White
dtype: object

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now