'Filter a dataframe based on string column
I have read a text file in jupyter notebook and want to fetch some sentences containing particular words. My code:
import pandas as pd
df = open(r"new2.txt", "rt")
contents = df.read()
print(contents)
df[df['text'].str.contains('possession|chemical report|S.|chemical examination|act|witness|appeal|dismissed|refused|judgement')]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
