0

I have a file in which I am willing to convert all the numbers in the columns of my dataframe like (1,2, etc..) to be converted to (one,two, etc..). Here is how my dataframe looks like:

name
a1printanddisplay.com
a1programador.com.br
a1web.com.br
a1weblink.com
a2 hosting
a2 hosting inc. iceland
a2 system international
a2 group llc

Does anybody know the quickest way to do that?

Paul H
  • 65,268
  • 20
  • 159
  • 136
UserYmY
  • 8,034
  • 17
  • 57
  • 71
  • is the range of numbers limited and known upfront or not? You could generate a list of all known numbers and their replacements call `df.name.str.replace('1', 'one')` etc.. – EdChum Apr 06 '15 at 20:32
  • @EdChum they are not known but I meant more any other way than normal replace. Is there any? – UserYmY Apr 06 '15 at 20:34
  • No not really depending on how your data is composed it may be quicker to just do 10 calls to replace which will be fast rather than creating some function that is called for each value – EdChum Apr 06 '15 at 20:43
  • @EdChum I do not agree because if I replace 1 with one for instance what about 51? Then it would be fiveone – UserYmY Apr 07 '15 at 07:05

1 Answers1

1

There are two approaches you could try. The first approach involves converting each digit individually. For example, 381 would become "three eight one"

The other approach is to convert the digits with their place-value context. For example, 381 would become "three hundred eighty-one"

For the first approach see: Is there a way to convert number words to Integers?

For the second approach, try num2words: https://pypi.python.org/pypi/num2words

Community
  • 1
  • 1
Jesuisme
  • 1,805
  • 1
  • 31
  • 41