2024-04-25 08:35:27 发布
网友
我试图找到Student列包含Yes的索引。下面的代码片段是我的试用版,但没有运气和抛出'str' object has no attribute 'astype'错误
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
有人能解释一下为什么会发生这种情况吗?我怎么可能解决呢
正如其他评论所提到的,可能您的学生列已经是字符串类型。如果您想得到它,请执行以下操作:
yesindex = deliveries.loc[deliveries['Students'].str.contains('Yes') == True].index
或者,如果要与小写字母匹配:
yesdindex = deliveries.loc[deliveries['Students'].str.lower().str.contains('yes') == True].index
正如其他评论所提到的,可能您的学生列已经是字符串类型。如果您想得到它,请执行以下操作:
或者,如果要与小写字母匹配:
相关问题 更多 >
编程相关推荐