Last active
October 14, 2020 08:33
-
-
Save sevperez/3c6233f846d98fd5e3e11e5c40c076f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_df_texts(df, query_string: str): | |
""" | |
- Parameters: df (Pandas DataFrame), query_string (string). df must | |
contain a "text" column. | |
- Returns: A subset of df containing only rows where each term in | |
query_string appeared as a substring in df["text"]. | |
""" | |
terms = query_string.lower().split(" ") | |
filters = [df["text"].str.lower().str.contains(term) for term in terms] | |
return df[np.all(filters, axis=0)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment