Note

Pandas (24) 본문

Pandas

Pandas (24)

알 수 없는 사용자 2022. 8. 15. 22:34
728x90

How to filter words that contain atleast 2 vowels from a series?

# Input
ser = pd.Series(['Apple', 'Orange', 'Plan', 'Python', 'Money'])

# Solution
from collections import Counter
mask = ser.map(lambda x: sum([Counter(x.lower()).get(i, 0) for i in list('aeiou')]) >= 2)
ser[mask]

# output
0     Apple
1    Orange
4     Money
dtype: object

'Pandas' 카테고리의 다른 글

Pandas (26)  (0) 2022.08.17
Pandas (25)  (0) 2022.08.16
Pandas (23)  (0) 2022.08.14
Pandas (22)  (0) 2022.08.13
Pandas (21)  (0) 2022.08.12
Comments