In this shot, we will learn about the replace_currency_symbols
in Python.
The replace_currency_symbols
method is an in-built method, provided by the clean-text
library in Python.
We can use it to clean data that has currency symbols in it.
We need to install it from pip
in order to use it in our programs:
pip install clean-text
We can use the following syntax to use it.
from cleantext import clean
clean(text, no_currency_symbols=True, replace_with_currency_symbol="")
clean
is the function provided by the cleantext
library.no_currency_symbols
to True
.<CUR>
by default.Let’s look at an example.
#import clean functionfrom cleantext import clean#provide string with currency symbolstext = "$4000, 9000€, 100000¥"#print text after replacing the currency symbolsprint(clean(text, no_currency_symbols=True, replace_with_currency_symbol=""))
In the code written above:
clean
function from the cleantext
package.text
with empty space. When the parameter no_currency_symbols
is set to True
, the clean
function will call the in-built replace_currency_symbols()
function.