data processsing python

Solutions on MaxInterview for data processsing python by the best coders in the world

showing results for - "data processsing python"
Aurélie
19 Aug 2016
1def filter(string):
2    stopwords   = ['their', 'during', 'doesn', "she's", 'ourselves', 'weren', 'll', 'has', 'had', 'we', 'not', 'if', 'will', 'such', 'needn', 'own', "isn't", "you'll", 'or', 'o', 'hadn', 'but', 'his', 'my', 'y', 'she', "doesn't", 'haven', 'herself', 'and', 'other', 'hasn', 'having', 'ain', 'doing', 'mustn', 'he', "that'll", 'being', 'most', 'did', 'is', 'same', "weren't", 'itself', 'yourselves', 'too', 'ma', 's', 'do', 'just', 'all', 'on', 'than', 'didn', 'couldn', 'some', 'until', 'under', 'your', 'its', 'a', 'further', 'isn', "needn't", 'over', 'below', 'where', 'theirs', 'to', 'more', "you'd", 'her', "shan't", 'with', 'while', 'nor', 'wouldn', "aren't", 'wasn', "won't", 'for', 't', 'aren', "mightn't", 'them', "couldn't", 'was', 'be', 'should', 'i', 'mightn', 'themselves', 'out', 'no', 'have', 'am', 'off', 'any', "don't", 'ours', 'it', 'are', 'by', "wasn't", 'each', 'whom', "haven't", 'yourself', 'won', "hasn't", "should've", 'me', 'can', 'when', 'only', 'now', 'm', 'above', 'up', 'in', 'does', 'because', 'myself', 'hers', 'of', 'into', 'very', 'between', 'here', 'the', 'why', 'after', 'yours', 'there', 'these', "you're", 'few', 'don', 'both', 'which', 'who', 're', 'that', 'through', 'before', 'd', "you've", 'as', 'shouldn', "wouldn't", 'an', 'about', 'those', 'how', "it's", 'been', 'what', "shouldn't", 'down', 'at', 'you', 'so', 'him', 'they', 'himself', 've', 'from', "hadn't", "mustn't", 'then', 'were', 'our', "didn't", 'again', 'against', 'once', 'shan', 'this']
3    res = re.sub(r'[^\w\s]', '', string.lower())   # removing punc
4    res = ''.join([i for i in res if not i.isdigit()]) #removing numbers
5    tokens =  res.split()
6    filtered_sentence = [w for w in tokens if not w in stopwords]  
7    for index,i in  enumerate(filtered_sentence):
8        if i.lower()[-1] == "s":
9            temp =  i.replace("s","")
10            #temp =  re.sub('s$','',i)
11            filtered_sentence[index] = temp
12    res = ' '.join(filtered_sentence)
13    pattern = re.compile(r'\s+') 
14    res= re.sub(pattern, '', res)  # removig spaces
15    return(res)
16
similar questions
queries leading to this page
data processsing python