-
-
Save amankharwal/2dd362d3515d21bf52db948fc008db1f 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
import re | |
def clean_text(df, text_field): | |
df[text_field] = df[text_field].str.lower() | |
df[text_field] = df[text_field].apply(lambda elem: re.sub(r"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)|^rt|http.+?", "", elem)) | |
return df | |
test_clean = clean_text(test, "tweet") | |
train_clean = clean_text(train, "tweet") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment