the prawgetdata(function retrieves the "hottesttopics in its subredditappends this to an arrayand then gets all its related comments this goes on until thousand topics are reached or no more topics exist to fetch and everything is stored in the sqlite database the print statements are there to inform you on its progress toward gathering thousand topics all that' left for us to do is execute the function for each subreddit if you' like this analysis to incorporate more than two subredditsthis is matter of adding an extra category to the subreddits array with the data collectedwe're ready to move on to data preparation step data preparation as alwaysdata preparation is the most crucial step to get correct results for text mining this is even truer since we don' even start off with structured data the upcoming code is available online as ipython file data preparation and analysis let' start by importing the required libraries and preparing the sqlite databaseas shown in the following listing listing text mininglibrariescorpora dependenciesand sqlite database connection import sqlite import nltk import matplotlib pyplot as plt from collections import ordereddict import random nltk download('punkt'nltk download('stopwords'import all required libraries download corpora we make use of conn sqlite connect('reddit db' conn cursor(make connection to sqlite database that contains our reddit data in case you haven' already downloaded the full nltk corpuswe'll now download the part of it we'll use don' worry if you already downloaded itthe script will detect if your corpora is up to date our data is still stored in the reddit sqlite file so let' create connection to it even before exploring our data we know of at least two things we have to do to clean the datastop word filtering and lowercasing general word filter function will help us filter out the unclean parts let' create one in the following listing