File tree Expand file tree Collapse file tree 5 files changed +1053
-1072
lines changed Expand file tree Collapse file tree 5 files changed +1053
-1072
lines changed Original file line number Diff line number Diff line change @@ -30,18 +30,9 @@ def f_124(text):
30
30
words 1
31
31
dtype: int64
32
32
"""
33
- # Normalize the text to lowercase
34
- text = text .lower ()
35
-
36
- # Use regex to find words, considering words as sequences of alphabetic characters
37
- words = re .findall (r'\b\p{L}+\b' , text )
38
-
39
- # Filter out stopwords
40
- filtered_words = [word for word in words if word not in STOPWORDS ]
41
-
42
- # Count the frequency of each word using pandas Series
43
- word_counts = pd .Series (filtered_words ).value_counts ()
44
-
33
+ words = re .findall (r"\b\w+\b" , text .lower ())
34
+ words = [word for word in words if word not in STOPWORDS ]
35
+ word_counts = pd .Series (words ).value_counts ().rename (None )
45
36
return word_counts
46
37
47
38
Original file line number Diff line number Diff line change @@ -30,10 +30,9 @@ def task_func(text):
30
30
words 1
31
31
dtype: int64
32
32
"""
33
- text = text .lower ()
34
- words = re .findall (r'\b\p{L}+\b' , text )
35
- filtered_words = [word for word in words if word not in STOPWORDS ]
36
- word_counts = pd .Series (filtered_words ).value_counts ()
33
+ words = re .findall (r"\b\w+\b" , text .lower ())
34
+ words = [word for word in words if word not in STOPWORDS ]
35
+ word_counts = pd .Series (words ).value_counts ().rename (None )
37
36
return word_counts
38
37
39
38
import unittest
Original file line number Diff line number Diff line change @@ -30,18 +30,9 @@ def f_124(text):
30
30
words 1
31
31
dtype: int64
32
32
"""
33
- # Normalize the text to lowercase
34
- text = text .lower ()
35
-
36
- # Use regex to find words, considering words as sequences of alphabetic characters
37
- words = re .findall (r'\b\p{L}+\b' , text )
38
-
39
- # Filter out stopwords
40
- filtered_words = [word for word in words if word not in STOPWORDS ]
41
-
42
- # Count the frequency of each word using pandas Series
43
- word_counts = pd .Series (filtered_words ).value_counts ()
44
-
33
+ words = re .findall (r"\b\w+\b" , text .lower ())
34
+ words = [word for word in words if word not in STOPWORDS ]
35
+ word_counts = pd .Series (words ).value_counts ().rename (None )
45
36
return word_counts
46
37
47
38
You can’t perform that action at this time.
0 commit comments