0

For example, after filtering the entire dataset to only questions containing the word "King", we could then find all of the unique answers to those questions.

I filtered by using the following code:

`def lower1(x):
   x.lower()

 filter_dataset = lambda x:all(x) in jeopardy.Question.apply(lower1) 
 print(filter_dataset(['King','England']))`

The above code is printing True instead of printing the rows of jeopardy['Question'] with the keywords 'King' and 'England'.

That is the first problem.

Now I want to count the unique answers to the jeopardy['Question']

Here is the sample data frame enter image description here

Now I want to create a function that does the count of the unique answers. I wrote the following code:

  `def unique_counts():
      print(jeopardy['Answer'].unique().value_counts())
   unique_counts()`

Which is giving me the following error:

AttributeError: 'numpy.ndarray' object has no attribute 'value_counts'

Karthik Bhandary
  • 1,305
  • 2
  • 7
  • 16

1 Answers1

1

Use Series.str.contains:

jeopardy[jeopardy['Question'].str.contains('|'.join(['King','England']))]
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58