0

here is the code!

dff=pd.read_csv('file.csv')

#finding those restaurant which have bar's at night
user=input('enter here')
dff[dff['Collections'].str.contains('user',na=False)]

in this code above the user will enter his choice of restaurant for instance user choose 'Bar', and then the code above will search the KEYWORD 'BAR' in the column name "collections" and return only those dataframe which consists of the keyword Bar in them. but this code is not working its returning me an empty dataframe. am using jupyter notebook

2 Answers 2

2

Problem

dff[dff['Collections'].str.contains('user', na=False)]

With quote, 'user' is a string in the above line. If nothing in Collections column contains "user" the result would be an empty DataFrame.

Solution

Remove the quote:

dff[dff['Collections'].str.contains(user, na=False)]

Sign up to request clarification or add additional context in comments.

Comments

0

First thing, you have a typo in last line of your code, user is a variable.

Update the last line to:

dff[dff['Collections'].str.contains(user,na=False)]

Another approach:

dff[dff['Collections'] == user]

You might need to check for Case with this approach.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.