Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nltk
- import string
- import numpy as np
- import pandas as pd
- from nltk.corpus import stopwords
- from keras.preprocessing.text import Tokenizer
- from keras.preprocessing.sequence import pad_sequences
- from keras.models import Sequential
- from keras.layers import LSTM
- from keras.layers.embeddings import Embedding
- np.random.seed(7)
- df = pd.read_csv('financial.csv')
- def clean(text):
- text=text.translate(string.punctuation)
- text=text.lower().split()
- stops = set(stopwords.words("english"))
- text = [w for w in text if not w in stops and len(w) >= 3]
- text = text.split()
- stemmer = SnowballStemmer('english')
- stemmed_words = [stemmer.stem(word) for word in text]
- text = " ".join(stemmed_words)
- return text
- df['text']=df['text'].map(lambda text: clean(text))
Add Comment
Please, Sign In to add comment