image_output_1.png
from nltk.stem.wordnet import WordNetLemmatizer

import matplotlib.pyplot as plt

import pandas as pd

import re

import pandas as pd
df = pd.read_csv('../input/bbc-text.csv')

import re
from nltk.stem.wordnet import WordNetLemmatizer
stop_words = ['in', 'of', 'at', 'a', 'the']
def pre_process(text):
    text = str(text).lower()
    text = re.sub('((\\d+)[\\.])', '', text)
    text = re.sub('&lt;/?.*?&gt;', ' &lt;&gt; ', text)
    text = text.replace('dont', "don't")
    text = re.sub("[^a-zA-Z0-9.']+", ' ', text)
    "\n    Don't include this in the beginning. \n    First check if there are some patterns that may be lost if we remove stopwords.\n    "
    text = [word for word in text.split(' ') if word not in stop_words]
    lmtzr = WordNetLemmatizer()
    text = ' '.join((lmtzr.lemmatize(i) for i in text))
    return text

for i in range(len(df)):
    df.text[i] = pre_process(df.text[i])

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 6))
df.groupby('category').text.count().plot.bar(ylim=0)
plt.show()