Skip to content
Advertisement

Catch fish by percentage – pygame

I want to create a fishing game. Whenever the player press a button, the game will return a fish. Every fish has a percentage ( small fish , 45% ; medium fish, 25% ; big, 15%; huge, 4.9%; shark,0.1). fish_size = [(“small”,45),(“medium”,25),(“big”,15),(“huge”,4.9),(“shark”,0.1)] How can I get a fish randomly from this list by percentage? Answer If you have a list

Pandas create column of dictionaries based on condition from another column

Let’s say if I have a Pandas df called df_1 like this: id date_created rank_1 rank_2 rank_3 rank_dict 2223 3/3/21 3:26 www.google.com www.yahoo.com www.ford.com {www.google.com:3, www.yahoo.com:2, www.ford.com:1} 1112 2/25/21 1:35 www.autoblog.com www.motor1.com www.webull.com {www.autoblog.com:3, www.motor1.com:2, www.webull.com:1} and another df called df_2 that looks like this: id date_created rank_1 rank_2 rank_3 2223 4/9/21 5:15 www.yahoo.com www.whatever.com www.google.com 1112 8/20/21 2:30 www.gm.com

Join columns in a single Pandas DataFrame

I’ve DataFrame with 4 columns and want to merge the first 3 columns in a new DataFrame. The data is identical, the order is irrelevant and any duplicates must remain. Desired DataFrame How do I get this done? Answer Here is one way of merging the first three columns with the help of numpy:

Draw rectangle on key click

I want to draw a rectangle with a button click , but the problem is with every loop it updates the display , display is filled with a color So the rectangle is only seen for a brief period of time. How to solve this. Answer You have to draw the rectangle in the application loop. For example add a

Advertisement