SearchInput pandas column with string contains and does not contain
Pandas
import pandas as pd
import numpy as np
Create a dataframe
#create a dataframe
raw_data = {'name': ['Willard Morris', 'Al Jennings'],
'age': [20, 19],
'favorite_color': ['blue', 'red'],
'grade': [88, 92],
'grade': [88, 92]}
df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings'])
df
age | favorite_color | grade | name | |
---|---|---|---|---|
Willard Morris | 20 | blue | 88 | Willard Morris |
Al Jennings | 19 | red | 92 | Al Jennings |
SearchInput pandas column with string contains
#here we can count the number of distinct users viewing on a given day
new_df = df[df['name'].str.contains('Morris', na=False)]
new_df.head()
age | favorite_color | grade | name | |
---|---|---|---|---|
Willard Morris | 20 | blue | 88 | Willard Morris |
SearchInput pandas column with string does not contain
#here we can count the number of distinct users viewing on a given day
new_df2 = df[~df['name'].str.contains('Morris', na=False)]
new_df2.head()
age | favorite_color | grade | name | |
---|---|---|---|---|
Al Jennings | 19 | red | 92 | Al Jennings |