Question

In: Computer Science

Python problem I don't know how to arrive to the answer of this question: "Rounded to...

Python problem

I don't know how to arrive to the answer of this question:

"Rounded to the nearest integer, how much higher is the average sum of all six stats among Mega Pokemon than their non-Mega versions? Note that Mega Pokemon share the same Number (the first column) as their non-Mega versions, which will allow you to find all Pokemon that have a Mega version."

For this problem below. The format of the file is included at the bottom but it's not complete. If you want the complete one, let me know and I can email it to you.

#The line below will open a file containing information
#about every pokemon through Generation 7:

pokedex = open('../resource/lib/public/pokedex.csv', 'r')

#We've also provided a sample subset of the data in
#sample.csv.
#
#Each line of the file has 13 values, separated by commas.
#They are:
#
#
# - Number: The numbered ID of the Pokemon, an integer
# - Name: The name of the Pokemon, a string
# - Type1: The Pokemon's primary type, a string
# - Type2: The Pokemon's secondary type, a string (this
# may be blank)
# - HP: The Pokemon's HP statistic, an integer in the range
# 1 to 255
# - Attack: The Pokemon's Attack statistic, an integer in
# the range 1 to 255
# - Defense: The Pokemon's Defense statistic, an integer in
# the range 1 to 255
# - SpecialAtk: The Pokemon's Special Attack statistic, an
# integer in the range 1 to 255
# - SpecialDef: The Pokemon's Special Defense statistic, an
# integer in the range 1 to 255
# - Speed: The Pokemon's Speed statistic, an integer in the
# range 1 to 255
# - Generation: What generation the Pokemon debuted in, an
# integer in the range 1 to 7
# - Legendary: Whether the Pokemon is considered "legendary"
# or not, either TRUE or FALSE
# - Mega: Whether the Pokemon is "Mega" or not, either TRUE
# or FALSE
#
#Use this dataset to answer the questions below.


#Here, add any code you want to allow you to answer the
#questions asked below over on edX. This is just a sandbox
#for you to explore the dataset: nothing is required for
#submission here.

Number,Name,Type1,Type2,HP,Attack,Defense,SpecialAtk,SpecialDef,Speed,Generation,Legendary,Mega
1,Bulbasaur,Grass,Poison,45,49,49,65,65,45,1,FALSE,FALSE
2,Ivysaur,Grass,Poison,60,62,63,80,80,60,1,FALSE,FALSE
3,Venusaur,Grass,Poison,80,82,83,100,100,80,1,FALSE,FALSE
3,Mega Venusaur,Grass,Poison,80,100,123,122,120,80,1,FALSE,TRUE
4,Charmander,Fire,,39,52,43,60,50,65,1,FALSE,FALSE
5,Charmeleon,Fire,,58,64,58,80,65,80,1,FALSE,FALSE
6,Charizard,Fire,Flying,78,84,78,109,85,100,1,FALSE,FALSE
6,Mega Charizard X,Fire,Dragon,78,130,111,130,85,100,1,FALSE,TRUE
6,Mega Charizard Y,Fire,Flying,78,104,78,159,115,100,1,FALSE,TRUE
7,Squirtle,Water,,44,48,65,50,64,43,1,FALSE,FALSE
8,Wartortle,Water,,59,63,80,65,80,58,1,FALSE,FALSE
9,Blastoise,Water,,79,83,100,85,105,78,1,FALSE,FALSE
9,Mega Blastoise,Water,,79,103,120,135,115,78,1,FALSE,TRUE
10,Caterpie,Bug,,45,30,35,20,20,45,1,FALSE,FALSE
11,Metapod,Bug,,50,20,55,25,25,30,1,FALSE,FALSE
12,Butterfree,Bug,Flying,60,45,50,90,80,70,1,FALSE,FALSE
13,Weedle,Bug,Poison,40,35,30,20,20,50,1,FALSE,FALSE
14,Kakuna,Bug,Poison,45,25,50,25,25,35,1,FALSE,FALSE
15,Beedrill,Bug,Poison,65,90,40,45,80,75,1,FALSE,FALSE
15,Mega Beedrill,Bug,Poison,65,150,40,15,80,145,1,FALSE,TRUE
16,Pidgey,Normal,Flying,40,45,40,35,35,56,1,FALSE,FALSE
17,Pidgeotto,Normal,Flying,63,60,55,50,50,71,1,FALSE,FALSE
18,Pidgeot,Normal,Flying,83,80,75,70,70,101,1,FALSE,FALSE
18,Mega Pidgeot,Normal,Flying,83,80,80,135,80,121,1,FALSE,TRUE
19,Rattata,Normal,,30,56,35,25,35,72,1,FALSE,FALSE
20,Raticate,Normal,,55,81,60,50,70,97,1,FALSE,FALSE

Solutions

Expert Solution

Here is the code:

# selecting Mega Pokemon
mega_pokemon = pokedex[pokedex['Mega'] == 1]
mega_pokemon = mega_pokemon.reset_index(drop = True) 
print('Total number: ',len(mega_pokemon))
mega_pokemon


# selecting nonMega Pokemon
nonMega_pokemon = pokedex[pokedex['Mega'] == 0]
nonMega_pokemon = nonMega_pokemon.reset_index(drop = True) 
print('Total number: ',len(nonMega_pokemon))

# selecting common rows based on Number
common_number = list(np.intersect1d(mega_pokemon.Number, nonMega_pokemon.Number))

# selecting index based on common_number
indices = list()
for loop1 in range(len(nonMega_pokemon)):
    for loop2 in range(len(mega_pokemon)):
        if(nonMega_pokemon.iloc[loop1][0] == mega_pokemon.iloc[loop2][0]):
            indices.append(loop1)
indices = list(set(indices))

# selecting rows based on indices
nonMega_pokemon = nonMega_pokemon.loc[indices]
nonMega_pokemon.head()


# Since with number 6, only one Pokemon is available in one group, removing other 6th Number
mega_pokemon = mega_pokemon.drop_duplicates(subset=['Number'])   # removing duplicate on Number
mega_pokemon


def avg_sum_stats(dataframe):     # calculate average sum of all the six stats
    average_sum  = dataframe.iloc[:,4:10]
    average_sum = list((dataframe.sum(axis=1)) / len(xyz))
    average_sum = [int(item+0.5) for item in xyz]
    
    return(average_sum)

avg_sum1 = avg_sum_stats(mega_pokemon)
avg_sum2 = avg_sum_stats(nonMega_pokemon)

differences = [x1 - x2 for (x1, x2) in zip(avg_sum1, avg_sum2)]
differences

Here is the results:

Data:

NonMega Pokemon:

Mega Pokemon

Currently, with the given data, both the types of pokemon are same strength values of stats.


Related Solutions

I have a problem, and I have the answer but I don't know where the solution...
I have a problem, and I have the answer but I don't know where the solution comes from. ( I have to be able to solve these myself so please help me by answering the questions about the problem.) Here is the answer given to me by the professor: What is the density of SF4 vapor at 650 torr and 100 C? 650 torr (1atm/760 Torr)=0.855atm 100C=373K PV=nRT n/v=P/RT= 0.855atm/0.8206l-atm/molek) (373)=0.0279 mole/l M.W. of SF4=108.1 gm/mole Density=mass/volume 0.0279 mole/l(108.1gm/mole) Answer...
I don't know how to solve this accounting problem. The problem is about Variance Analyses. Problem:...
I don't know how to solve this accounting problem. The problem is about Variance Analyses. Problem: Materials, Labor and Factory Overhead.(CPA, adapted) The Palmtown Furniture Company uses a standard cost system in accounting for its production costs. The standard cost of a unit of furniture follows:                     Lumber, 100 feet @$150 per 1,000 feet                                $15.00           Direct labor, 4 hours @ 2.50 per hour                                    10.00           Factory overhead:                       Fixed (30% of direct labor)                $3.00                       Variable (60% of...
Below is a diffraction problem. I have the solutions to the problem but I don't know...
Below is a diffraction problem. I have the solutions to the problem but I don't know how to arrive at these solutions. A) In an experiment two slits are separated by 0.22mm and illuminated by light of wavelength 640nm. How far must a screen be placed in order for the bright fringes to be separated by 5 mm? (1.72 m) B) A soap film is illuminated by white light normal to its surface. The index of refraction of the film...
HI, I hope you are doing well. I really don't understand this question and don't know...
HI, I hope you are doing well. I really don't understand this question and don't know how to solve it at all because I am completely new to this c++ programming. can you please explain each line of code with long and clear comments? please think of me as someone who doesn't know to code at all. and I want this code to be written in c++ thank you very much and I will make sure to leave thumbs up....
I've seen this question answered for C but I don't know how to translate to Java....
I've seen this question answered for C but I don't know how to translate to Java. Write a program that requests the hours worked in a week and the basic pay rate, and then prints the gross pay (before tax), the taxes, and the net pay (after tax). Assume the following: Basic pay rate: from user's choice Overtime (in excess of 40 hours) = time and a half (i.e., if the hours worked is 45, the hours for pay will...
please I don't really know how to start answering this question I really need to understand...
please I don't really know how to start answering this question I really need to understand it please show the work with a clear handwriting A collision in one dimension A mass m1 = 2 kg moving at v1i = 3 ms−1 collides with another mass m2 = 4 kg moving at v2i = −2 ms−1. After the collision the mass m1 moves at v1f = −3.66 ms−1. (a) Calculate the final velocity of the mass m2. (b) After the...
I know the what the answers are but I don't know how to get them. Can...
I know the what the answers are but I don't know how to get them. Can you please explain the process? Thank you. Part VII. Discontinued Operations and Earnings per Share (11 points) Todd Corporation had pre-tax income for 2017 of $2,500,000. On December 31, 2017, Boyd disposed of a component of its business that represented a strategic shift in operation. That component had a Loss on Discontinued Operations of $450,000 (pre-tax). Boyd received $1,000,000 net cash proceeds from the...
I saw an answer for this on another question posted, but I don't think the answer...
I saw an answer for this on another question posted, but I don't think the answer was exactly what I was looking for. Can anyone help guide me in the right direction in regards to this question and its subquestions? Thanks. The proton and electron are particles found to have equal and opposite charges to the precision that the measurements have been made so far. Why is it important that the proton and electron have exactly the same magnitude for...
greetings, I don't understand how to answer the question "static and flexible budget" or how to...
greetings, I don't understand how to answer the question "static and flexible budget" or how to determine if customer support controled their costs well. Thanks for your help
I am trying to solve this problem, but I don't know which test to use: For...
I am trying to solve this problem, but I don't know which test to use: For average risk funds only, test the proportion of funds with Sales Charges is not 50% use α = 0.10. Explain your conclusion. Here is the contingency table with the data: Sales charge Yes No total Risk Low 6 8 14 Avg 42 34 76 High 24 23 47 Total 72 65 137 Context of the problem: Mutual funds are the most common way people...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT