我有一个熊猫数据帧,它有以下列
affix, word, sense and meaning
。现在,如果我想获得列word
中的所有条目,其最后一个字符的第四个字符是a
。你知道吗
下面的片段为我提供了答案
pd[(pd['affix'] == 'man') & (pd['word'].str[-4] == 'a' ) ]
输出为
affix word sense meaning
9900 man cameraman who # somebody who operates a [[movie]] [[camera]]...
9901 man cameraman who # {{l|en|cameraman}} {{gloss|somebody who oper...
但是,如果我想保存最后一个字符的第四个字符是元音的条目,那么下面的代码片段就不起作用了。任何帮助都有助于取得成果
pd[(pd['affix'] == 'man') & (pd['word'].str[-4] in ['a','e','i','o','u'] ) ]
显示的错误是
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
可以与^{} 匹配
'.*[aeiou].{3}$'
是一个正则表达式,表示:'.*'
匹配任意次数'[aeiou]'
后跟括号之间列表中的单个字符'.{3}$'
后跟任意3个字符,然后后跟字符串的结尾。你知道吗我想你需要^{} :
相关问题 更多 >
编程相关推荐