400万行のデータフレーム内の部分文字列または複数の部分文字列を検索しています。pandas dataframe str.contains検索の高速化の方法
df[df.col.str.contains('Donald',case=True,na=False)]
または
df[df.col.str.contains('Donald|Trump|Dump',case=True,na=False)]
DATAFRAME(DF)下記(400万文字列の行を持つ)のように見えます
df = pd.DataFrame({'col': ["very definition of the American success story, continually setting the standards of excellence in business, real estate and entertainment.",
"The myriad vulgarities of Donald Trump—examples of which are retailed daily on Web sites and front pages these days—are not news to those of us who have",
"While a fearful nation watched the terrorists attack again, striking the cafés of Paris and the conference rooms of San Bernardino"]})
が速く、この文字列検索を行うための任意のヒントはありますか? たとえば、データフレームを最初にソートし、特定の索引付け方法で、列名を数値に変更し、問合せから「na = False」を削除しますか?スピードアップの数ミリ秒も非常に便利です!