Created
June 5, 2020 20:24
-
-
Save aniruddha27/239b60c8da20288083753b3c6c2ed9c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to preprocess speech | |
def clean(text): | |
# removing paragraph numbers | |
text = re.sub('[0-9]+.\t','',str(text)) | |
# removing new line characters | |
text = re.sub('\n ','',str(text)) | |
text = re.sub('\n',' ',str(text)) | |
# removing apostrophes | |
text = re.sub("'s",'',str(text)) | |
# removing hyphens | |
text = re.sub("-",' ',str(text)) | |
text = re.sub("— ",'',str(text)) | |
# removing quotation marks | |
text = re.sub('\"','',str(text)) | |
# removing salutations | |
text = re.sub("Mr\.",'Mr',str(text)) | |
text = re.sub("Mrs\.",'Mrs',str(text)) | |
# removing any reference to outside text | |
text = re.sub("[\(\[].*?[\)\]]", "", str(text)) | |
return text | |
# preprocessing speeches | |
df['Speech_clean'] = df['Speech'].apply(clean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment