[英]Python 'str.contains' function not returning correct values
[英]'str.contains' not returning values in dataframe
我正在清理一些文本數據,但無法找到包含某些字符串的行。 如果我做一個簡單的布爾值,我得到:
'<! [CDATA[! function( d,s, id){varjs, fjs=d. getElementsByTagName( s)[0],p= ^' in articles.loc[25111, 'content']
True
但是,如果選擇具有相同字符串的行,則會得到一個空的數據框:
articles[articles['content'].str.contains('<! [CDATA[! function( d,s, id){varjs, fjs=d. getElementsByTagName( s)[0],p= ^')]
id title author date content year month publication category digital section url stems
為什么會這樣?
我認為有些值被讀取為regex,因此在str.contains
需要參數regex=False
。
s = '<! [CDATA[! function( d,s, id){varjs, fjs=d. getElementsByTagName( s)[0],p= ^'
articles[articles['content'].str.contains(s, regex=False)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.