int argument must be a string a bytes-like object or a number not NoneType

0 votes

Hello, 

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.

when i am trying to convert in to int16, is is showing an error.

data['age']= data['age'].astype(np.int16)

int() argument must be a string, a bytes-like object or a number, not 'NoneType'

How shoul i overcome this error. It is a the coumns of a DataSet for ML. 

Mar 3, 2021 in Python by vijaybhargav

edited Mar 4, 2025 487 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP