Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
clean-text
communitycreator

What is replace_currency_symbols clean-text in Python?

Gutha Vamsi Krishna

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

Syntax

from cleantext import clean

clean(text, no_currency_symbols=True, replace_with_currency_symbol="")
  • clean is the function provided by the cleantext library.
  • To replace the currency symbols, we set the parameter no_currency_symbols to True.
  • Then, we provide the string with which to replace the currency symbols. If we don’t provide the string, the currency symbols will be replaced with <CUR> by default.

Let’s look at an example.

Code example

#import clean function
from cleantext import clean
#provide string with currency symbols
text = "$4000, 9000€, 100000¥"
#print text after replacing the currency symbols
print(clean(text, no_currency_symbols=True, replace_with_currency_symbol=""))

Code explanation

In the code written above:

  • In line 1, we import the clean function from the cleantext package.
  • In line 5, we provide the text that has currency symbols in it.
  • In line 8, we replace the currency symbols present in the 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.

RELATED TAGS

python
clean-text
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring