0

I am trying to convert an object dtpye column to int16 in pandas dataframe. Whereas my columns has data as shown below: The values are present as string and has trailing spaces.

dict = {'age' : [' 35', ' 23', ' 22', ' 24', ' 65', ' 28', ' 25', ' 26', ' 53', ' 27', ' 32', ' 37',' NA',  '102', '104', '111', '107', '109', '105', '112', '115', '110', '116', '108', '113', 37, 81, 43, 30, 45, 41,67,59,46]
       }

data =pd.DataFrame(data = dict, columns =['age'])

i have replaced the ' NA' value to 'None'(as it would be an null value to python.

data = data.replace({' NA': None })

and thereafter i have used data = data.replace({' NA': None })

but its not working and also i have a point here, I have removed trailing spaces and tried but it was not working.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

0 Answers0