Python Forum

Full Version: Problem with pandas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sample data:
Output:
business_name john chin elementary school sutter pub and restaurant sri thai cuisine washington bakery & restaurant brothers restaurant
The goal is to filter out which of these contain the word 'restaurant'.

I tried the following:
import pandas as pd

a = sf_restaurant_health_violations['business_name'].to_frame()
a['is_restaurant'] = a['business_name'].str.lower().isin(['restaurant'])
print(a)
..and I get the following output:

Output:
business_name is_restaurant john chin elementary school FALSE sutter pub and restaurant FALSE sri thai cuisine FALSE washington bakery & restaurant FALSE brothers restaurant FALSE
The desired output is:

Output:
john chin elementary school FALSE sutter pub and restaurant TRUE sri thai cuisine FALSE washington bakery & restaurant TRUE brothers restaurant TRUE
Would appreciate some assistance here.

Thanks