列名に基づいて(テキストを含む)データフレームでフィルタリングしたい。特定の列について、アイテムに列の名前が含まれている場合は維持され、含まれていない場合は削除されます。特定の行の内容は同じです。
このデータフレームを検討してください:
dog cat monkey
The cat is beautiful The cat is beautiful The cat is beautiful
The dog is beautiful The dog is beautiful The dog is beautiful
The monkey is beautiful The monkey is beautiful The monkey is beautiful
そして何が期待されますか:
dog cat monkey
The dog is beautiful The cat is beautiful The monkey is beautiful
ありがとうございます、
よろしく、
あなたはこれを試すことができます:
df.where(df.apply(lambda x: x.str.contains(x.name))).bfill().head(1)
出力:
dog cat monkey
0 The dog is beautiful The cat is beautiful The monkey is beautiful
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加