为什么我得到'str'对象没有属性'astype'`

时间:2020-05-18 22:36:47

标签: python pandas

我试图找到Student列包含Yes的索引。下面的代码段是我的试用版,但没有运气,并抛出'str' object has no attribute 'astype'错误。

  rule=lambda x: x.astype(str).str.lower.contains('Yes')
  yesindex = teaching.loc[teaching['Students'].apply(rule)].index

有人可以向我解释为什么会这样吗?我该如何解决?

1 个答案:

答案 0 :(得分:0)

正如其他评论所述,您的“学生”列可能已经是字符串类型。如果要获取它,请执行以下操作:

yesindex = deliveries.loc[deliveries['Students'].str.contains('Yes') == True].index

或者如果您想使用小写字母:

yesdindex = deliveries.loc[deliveries['Students'].str.lower().str.contains('yes') == True].index