I am working on to build a bag of words model from my text file. I I want to use the re.sub
function from the re library. I am getting the following error;
TypeError: expected string or bytes-like object
I have coded the following;
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
""" importing data set """
from nltk.corpus import PlaintextCorpusReader
corpus_root = './'
wordlists = PlaintextCorpusReader(corpus_root, 'evidence1.txt')
wordlists.fileids()
wordlists.words('evidence1.txt')
stringx = wordlists.words(wordlists.fileids()[0])
print (stringx)
""" cleaning the texts """
from nltk.text import Text
text = Text(stringx)
print(text)
import re
lowerx = re.sub('[^a-zA-Z0-9]','',text)
I think I need right kind of object to pass on to re.sub