本文介绍了无法将系列转换为< class'int'`>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组带有年龄"列的数据.我要删除所有年龄大于90岁且小于1856年的行.
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.
这是df的负责人:
这是我尝试的:
推荐答案您的错误是第2行.df['intage'] = int(df['age'])无效,您无法将pandas系列传递给int函数.
Your error is line 2. df['intage'] = int(df['age']) is not valid, you can't pass a pandas series to the int function.
如果df ['age']是对象dtype,则需要使用astype.
You need to use astype if df['age'] is object dtype.
df['intage'] = df['age'].astype(int)或者因为要减去两个日期,所以需要使用带days属性的dt访问器来获取天数为整数
Or since you are subtracting two dates, you need to use dt accessor with the days attribute to get the number of days as an integer
df['intage'] = df['age'].dt.days更多推荐
无法将系列转换为< class'int'`>
发布评论