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'

2
  • What do you mean by failed?? Apr 8, 2021 at 6:59
  • Added better dupe for check by substrings.
    – jezrael
    Apr 8, 2021 at 7:23

1 Answer 1

1

Use Series.str.contains:

jeopardy[jeopardy['Question'].str.contains('|'.join(['King','England']))]
14
  • Answer was closed.
    – jezrael
    Apr 8, 2021 at 7:00
  • Let's wait for OP to comeback if this is what he wants. If he wants something else, question might need to be reopened. Apr 8, 2021 at 7:02
  • I don't know why but the question was closed. Apr 8, 2021 at 7:03
  • @KarthikBhandary - Is isin what need ? Or something else?
    – jezrael
    Apr 8, 2021 at 7:04
  • I am saying that I want to create a dataset out of the jeopardy.Question I used the isin but it created an empty dataset. Apr 8, 2021 at 7:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.