Skip to content
Advertisement

Cannot convert the series to [closed]

I have a set of data with an Age column. I want to remove all the rows that are aged more than 90 and less than 1856.

This is the head of the dataframe:

Enter image description here

This is what I attempted:

Enter image description here

Advertisement

Answer

Your error is on line 2. df['intage'] = int(df['age']) is not valid, and you can’t pass a pandas series to the int function.

You need to use astype if df[‘age’] is object dtype.

df['intage'] = df['age'].astype(int)

Or since you are subtracting two dates, you need to use the dt accessor with the days attribute to get the number of days as an integer:

df['intage'] = df['age'].dt.days
Advertisement