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:
This is what I attempted:
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