text_html_output_1.png
import pandas as pd

import re

import seaborn as sns

data_train = pd.read_csv('../input/nlp-getting-started/train.csv')
data_test = pd.read_csv('../input/nlp-getting-started/test.csv')

data_train = data_train[['id', 'text', 'target']]
data_test = data_test[['id', 'text']]

s = data_train.target.value_counts()

def clean_text(data):
    data['clean_text'] = data['text'].str.lower()
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('http\\S+', '', elem))
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('[^\\w\\s]', '', elem))
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('/n', '', elem))
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('\\d+', '', elem))
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('\\s+', ' ', elem))
    data['clean_text'] = data['clean_text'].apply(lambda elem: re.sub('\\s+[a-zA-Z]\\s+', ' ', elem))
    return data

data_train = clean_text(data_train)
data_test = clean_text(data_test)

print(data_train['text'][2])
print(data_train['clean_text'][2])
print('  ')
print(data_test['text'][2])
print(data_test['clean_text'][2])