This is Jeopardy Challenge Project (Python, Pandas)

Anybody feel like helping me out?

I’m trying to build out a game, at the bottom of my project, but I’m stuck.

I’m trying to have the user select a category via input. I built out a dict with 6 random categories, shown like {1: ‘Category 1’, 2: ‘Category 2’…} but for the life of me I cannot figure out how to get it to work. As far as i can tell my code should work: it asks “if [user input] in [dictionary]” break and continue on, else tell them how to pick and try again. But typing the key doesn’t work, it doesn’t think it’s in the dictionary, which is how I thought it should work; typing the item doesn’t help either, so I don’t know what it thinks is in the dictionary. Can you take a look at my code and tell me where I’ve gone wrong? GitHub - brothertrance/This-is-Jeopardy-Terrance: Project Repository for This Is Jeopardy by Terrance

Much appreciated!

Hey Terrance, I looked at your code. ‘categories’ is a dictionary, so you need to just change one line:
catans in categories to catans in categories.values()

This should work because the category is a value in the dictionary. When using ‘in’, it checks the keys. Even when you type the number in your code, it still returns False. This is because the key is an integer while the input from the user is a string.

Hope this helps and happy coding!

Ugh thank you! That was driving me bananas.

Big thanks to @robertpal7899360306 for the code help, here’s my final (for now) version, down at the bottom I built out a whole game if you want to play around! Or just give me any tips or pointers in my code, that’s awesome too.

(Yes I know I need to get better at commenting in my code, I’m working on it. Right now I’m lazy.)

Glad you got your game to work! Well done.

1 Like

Hello guys, I’ve tried to look up keyword like REGEX here and Google. Still, I couldn’t find a way to solve the problem. Can anyone here help me out? I’d be really appreciated! :pleading_face:

So, in task 3 about the filter function, it said

You may also want to check to make sure you don’t find rows that contain substrings of your given words. For example, our function found a question that didn’t contain the word "king" , however it did contain the word "viking" — it found the "king" inside "viking"

If I don’t want the filter function to count VIKING in the searching for KING the keyword. Or, don’t count ‘England’s’ with the keyword ‘England.’ How do I apply regex in my function?

I know I could probably add regex ‘\s’ before and after the keyword.But how exactly I can apply the regex, in this case, to a list of words?

I’ve come up with something like this. But apparently it didn’t work…

import re def regex_filter_data(data, words): pat_words = [] filtered_df = pd.DataFrame() for word in words: pat = r'\s{word}\s' pat_words.append(pat) for word in pat_words: pd.concat([filtered_df, data[data['Question'].str.contains(pat=word, na = False, case=False, regex=True)]]) return filtered_df print(regex_filter_data(df, ['king', 'England]))

Hello Codecademy!

Here is my solution to the “This is Jeopardy” project. All feedback is welcome!

https://github.com/zcronk62/this_is_jeopardy

Happy coding!

Hello all…
The Jeopardy Challenge Project has been a challenge. I am jumping back into Codecademy after a long break and found some of the work leading up to this challenge fairly simple to catch up on, but some of it seemed to be not fully explained. This challenge took quite a bit of research on my own to complete. I am still working off-platform on a Jeopardy-style game with my own data set. It will take some time, but will be published on my GitHub when it’s done.

Anyway, here is the code I used to complete the second suggestion on part 7 - Is there a connection between the round and the category?
I got help from Stack Overflow on this one as I couldn’t figure out how to get the Categories to aggregate.
(Python Pandas Count of unique column values based on another column - Stack Overflow)

#7b
#Find percentage of questions per category per round.
#Create new df with only necessary columns.
cat_round_df = jeopardy_[["Category", "Round"]]

#Percentage category appears in each round.
cats_per = (cat_round_df.groupby('Category')['Round']
   .value_counts(normalize=True).mul(100).round(2)
   .sort_index()
   .to_frame(name='Result_%')
).reset_index()
print(cats_per.tail(50))

The resulting dataframe shows the % of each Category that appears in that particular Round of Jeopardy.
(excerpt)

1141  WORKING ON THE RAILROAD           Jeopardy!         100.00  
1142  WORLD "P"s                        Jeopardy!         100.00  
1143  WORLD AUTHORS                     Jeopardy!         100.00  
1144  WORLD BOOK DESCRIBES THE "G" MAN  Jeopardy!         100.00  
1145  WORLD CAPITALS                    Double Jeopardy!  83.33   
1146  WORLD CAPITALS                    Final Jeopardy!   16.67   
1147  WORLD CITIES                      Final Jeopardy!   100.00  
1148  WORLD FACTS                       Double Jeopardy!  100.00  
1149  WORLD GEOGRAPHY                   Double Jeopardy!  62.50   
1150  WORLD GEOGRAPHY                   Final Jeopardy!   6.25    
1151  WORLD GEOGRAPHY                   Jeopardy!         31.25   
1152  WORLD HISTORY                     Jeopardy!         100.00  
1153  WORLD HODGEPODGE                  Jeopardy!         100.00  
1154  WORLD LEADERS                     Double Jeopardy!  71.43   
1155  WORLD LEADERS                     Final Jeopardy!   28.57   
1156  WORLD MUSEUMS                     Double Jeopardy!  100.00  
1157  WORLD RELIGION                    Double Jeopardy!  100.00  
1158  WORMS                             Jeopardy!         100.00

Further exploration could be done to determine which categories or Subjects are more prominent in each Round or by adding a column for average Value of each Category per Round.

1 Like

Hello everyone!

In the next link you can find my solution to the “This is Jeopardy” project.

Here is my project! Thanks for checking it out!

Hello, in the 4th problem, I constantly get TypeError: ‘int’ object is not subscriptable, even when I pretty much copy pasted the code from solutions. Any help would be appreciated.

The code:

jeopardy["Float Value"] = jeopardy["Value"].apply(lambda x: float(x[1:].replace(',','')) if x != "None" else 0)


print(jeopardy['Float Value'])

Error:

TypeError                                 Traceback (most recent call last)
/var/folders/q6/n8kchxdn56s1hfqg5z7clg940000gn/T/ipykernel_17091/4251766879.py in <module>
----> 1 jeopardy["Float Value"] = jeopardy["Value"].apply(lambda x: float(x[1:].replace(',','')) if x != "None" else 0)
      2 
      3 
      4 print(jeopardy['Float Value'])

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwargs)
   4431         dtype: float64
   4432         """
-> 4433         return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
   4434 
   4435     def _reduce(

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in apply(self)
   1086             return self.apply_str()
   1087 
-> 1088         return self.apply_standard()
   1089 
   1090     def agg(self):

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in apply_standard(self)
   1141                 # List[Union[Callable[..., Any], str]]]]]"; expected
   1142                 # "Callable[[Any], Any]"
-> 1143                 mapped = lib.map_infer(
   1144                     values,
   1145                     f,  # type: ignore[arg-type]

~/opt/anaconda3/lib/python3.9/site-packages/pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

/var/folders/q6/n8kchxdn56s1hfqg5z7clg940000gn/T/ipykernel_17091/4251766879.py in <lambda>(x)
----> 1 jeopardy["Float Value"] = jeopardy["Value"].apply(lambda x: float(x[1:].replace(',','')) if x != "None" else 0)
      2 
      3 
      4 print(jeopardy['Float Value'])

TypeError: 'int' object is not subscriptable
1 Like

Why do I get this error?

Thanks in advance

Hi coders!

Here my version of the Jeopardy! Game. Please download a copy and tell me how it is play with it. Your feedback will be very appreciate!

Happy Coding!

Rather than ask people to download your project, push it to a GitHub repo and then people can view it there.

1 Like

Hi lisalisaj,

Thank you for the feedback. For sure I wrote the post in a very bad way. I would like people give me feedback if and how they enjoy the quiz game as I wrote in the Readme file. Now as I’m new in coding and I really don’t know so much on GitHub, I tough that there is no way to run the code in GitHub without download it. If there is a way, please let me know!
Anyway, the project is already in GitHub. Hope that you can see it.
I’ll write the link again.
Hope that now my intent are clear.

Have a nice coding!

https://github.com/Z-Marta/Jeopardy

1 Like

No worries! :slight_smile:

In GH, it’s a static file. Anyone can view the notebook, they can’t run the code cells tho. (unless you set the perms so ppl can create pull requests for it, edit, etc).
If you wanted to allow it to be interactive (viewers could run the code cells), you could open the .ipynb file & save the file in Google Colab, push a copy to GH, and when people view it (if they have Colab), they can open it in in Colab from GH (as a viewer, you have to set the permissions in google).

It sounds more complicated than it is, but it’s really not. Colab is built like Jupyter and you can write and execute Python code in it. It’s an app you add to your Google Drive. It’s got tons of documentation as well. It’s pretty easy to use.

1 Like

Hi All,

This is my code.

I’m still trying to figure out the best way to document my code. I like commenting in python because you can follow step by step but I’ve also heard the importance of using README.md files. Let me know if my comments are too much/not necessary.

Hello team,
I just completed the Jeopardy project. It was nothing short of a great challenge.

I’m happy to get everyone’s review on my code here.