-2

I have a dataframe with a column called Age, which I am trying to convert to numeric. One of the values in the column is text "seven". How do I get this done using Python, so that the text gets converted to number 7? Am looking at an option where I don't need to loop through each row and convert on a case basis. Please help

SNT
  • 1
  • 2
  • Did see similar questions. but all of those read row by row through a for loop. Is there a way to check for presence of strings without looping through and get them converted? – SNT Oct 25 '17 at 00:05

1 Answers1

0

One option is to hardcode a list containing ['zero', 'one', 'two'] up to highest age. Then you can get the index based on the number from the database.

 >>>number = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven']
 >>>index = number.index('seven')
 >>>print(index)
 7

See this example.

ronald kok
  • 38
  • 7