clean-text
package?Clean-text is a third-party package used to pre-process text data to obtain a normalized text representation.
The package can be installed via pip. Check the following command to install the clean-text package.
pip install clean-text
replace_numbers()
methodThe replace_numbers()
method is used to replace all the numbers in the given text with the replacement string.
replace_numbers(text, replace_with="<NUMBER>")
text
: This is the text data whose numbers we want to replace with the replacement string.replace_with
: This is the replacement string we are replacing the numbers with.This method returns the text data where all the numbers are replaced with the string.
import cleantextstring = """hello educative - 234123 - hello edpresso"""new_string = cleantext.replace_numbers(string, replace_with="number_was_here")print("Original String - '" + string + "'")print("Modified String - '" + new_string + "'")
cleantext
package.number_was_here
using the replace_numbers()
method.