Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with pandas
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas : problem with conditional filling of a column Xigris 2 594 Jul-22-2023, 11:44 AM
Last Post: Xigris
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 883 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Problem in saving .xlsm (excel) file using pandas dataframe in python shantanu97 2 4,164 Aug-29-2021, 12:39 PM
Last Post: snippsat
  CGI in python, problem with pandas, plotly.express and export html HK2432 0 2,100 Jan-19-2020, 01:30 PM
Last Post: HK2432

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020