Guest User

Untitled

a guest
May 25th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import nltk
  2. import string
  3. import numpy as np
  4. import pandas as pd
  5. from nltk.corpus import stopwords
  6. from keras.preprocessing.text import Tokenizer
  7. from keras.preprocessing.sequence import pad_sequences
  8. from keras.models import Sequential
  9. from keras.layers import LSTM
  10. from keras.layers.embeddings import Embedding
  11. np.random.seed(7)
  12. df = pd.read_csv('financial.csv')
  13. def clean(text):
  14. text=text.translate(string.punctuation)
  15. text=text.lower().split()
  16. stops = set(stopwords.words("english"))
  17. text = [w for w in text if not w in stops and len(w) >= 3]
  18. text = text.split()
  19. stemmer = SnowballStemmer('english')
  20. stemmed_words = [stemmer.stem(word) for word in text]
  21. text = " ".join(stemmed_words)
  22. return text
  23. df['text']=df['text'].map(lambda text: clean(text))
Add Comment
Please, Sign In to add comment