Skip to content

Instantly share code, notes, and snippets.

@swayson
Created June 8, 2015 07:16
Show Gist options
  • Save swayson/454da05a03b60dc616ec to your computer and use it in GitHub Desktop.
Save swayson/454da05a03b60dc616ec to your computer and use it in GitHub Desktop.
Basic snippet for searching items
def search_item(dataframe, name, query, na=False, case=False, regex=True):
idx = pd.Series([False]*len(dataframe))
# For each item in the query look for the item and collect the documents ids it pertains to
for q in query:
matches = dataframe[text_column].str.contains(q, na=False, case=False, regex=True)
idx = (idx) | (matches)
dataframe.loc[idx, name] = 1
dataframe.loc[:, name] = dataframe.loc[:, name].fillna(0)
return dataframe
def make_dataframe():
df = pd.DataFrame(dict(a=['a', 'b', 'c'], b=['A', 'B', 'C'])
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment