text_html_output_1.png
from sklearn.feature_extraction.text import CountVectorizer

import pandas as pd

import re

import string

review_text_train = pd.read_csv('../input/review_text_train.csv', index_col=False, delimiter=',', header=0)
review_text_test = pd.read_csv('../input/review_text_test.csv', index_col=False, delimiter=',', header=0)
review_meta_train = pd.read_csv('../input/review_meta_train.csv', index_col=False, delimiter=',', header=0)
review_meta_test = pd.read_csv('../input/review_meta_test.csv', index_col=False, delimiter=',', header=0)

df_train = review_text_train.copy()

df_train.isna().sum()

def clean_text_round_1(text):
    text = text.lower()
    text = re.sub('[%s]' % re.escape(string.punctuation), '', text)
    text = re.sub('\\w*\\d\\w*', '', text)
    return text
round_1 = lambda x: clean_text_round_1(x)

data_review_cleaned = pd.DataFrame(df_train.review.apply(round_1))

def clean_text_round_2(text):
    text = re.sub('\n', ' ', text)
    text = re.sub('[""..._]', '', text)
    return text
round2 = lambda x: clean_text_round_2(x)

data_review_cleaned = pd.DataFrame(data_review_cleaned.review.apply(round2))

from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(stop_words='english')
data_cv = cv.fit_transform(data_review_cleaned.review)
data_dtm = pd.DataFrame(data_cv.toarray(), columns=cv.get_feature_names())
data_dtm.index = data_review_cleaned.index
data_dtm