This problem involves some simple data analysis and aims to give you some more practice with combining Python data structures in interesting ways: in this case, using two-level dictionaries (i.e., a dictionary of dictionaries). The data, as it happens, is about Pokemon (source: www.kaggle.com). You are to write a program to read in Pokemon data from a file and organize it according to Pokemon type (we will only consider Type 1 for this assignment), then repeatedly read in queries from the user and print out solutions to those queries.
The input file, Pokemon.csv, is in CSV format (“comma-separated values”). This is a simple file format typically used for tabular data such as that for spreadsheets, and if you want you can open this file in a program like Excel or libreoffice to view the data in an easier-to-read form.
Any line in the input file that begins with the character ‘#‘ (without quotes) is a comment line that should be ignored for data analysis.
The first line of the input file, which is a comment line, gives the meaning of the various data columns (in this table, the number at the top of each entry gives its position in a row of comma-separated values, e.g., “Attack” is at position 6):
0
No.1
Name2
Type 13
Type 24
Total strength5
HP6
Attack7
Defense8
Special Attack9
Special Defense10
Speed11
Generation12
Legendary?
Write a program, in a file pokemon.py, that behaves as follows.
Your program will read in queries from the user, and for each query, analyze the Pokemon data based on the query and print out the results (see Output Format below). The queries and the corresponding analyses are as follows:
User query Program action Total Compute the Pokemon type(s) that have highest average Total strength. HP Compute the Pokemon type(s) that have highest average HP. Attack Compute the Pokemon type(s) that have highest average Attack. Defense Compute the Pokemon type(s) that have highest average Defense. SpecialAttack Compute the Pokemon type(s) that have highest average Special Attack. SpecialDefense Compute the Pokemon type(s) that have highest average Special Defense. Speed Compute the Pokemon type(s) that have highest average Speed. (empty line) Terminate query processing anything else Ignore the query
Note that, in each case, there may be more than one type of Pokemon with the highest average value computed. You should print out information about each of them according to the output format given below.
Matching the queries entered by the user’s with the User query column shown above should be case-insensitive. For example, the user inputs Attack, attack, ATTACK, and AtTaCk should all be processed the same way.
For each Pokemon type identified by your analysis, print out the result as follows:
print("{}: {}".format(pokemon_type, max_average))
where pokemon_type is the type of Pokemon, and max_average is the average value computed for that Pokemon type for that query (e.g., average total, average HP, average Attack, etc.), which should be equal to the maximum value for that query across all types.
Additionally, for each Pokemon type you should pre-compute the average values for all of its properties (see Code Organization below). These average values should also be organized as a dictionary keyed by Pokemon type.
Some examples of query processing, on different datasets, are shown here.
It can be helpful, for testing and debugging, to start out with small input files and work up to larger inputs. In addition to the full Pokemon.csv dataset, the examples below also use four smaller slices of the full dataset. In each case, the program had four queries submitted (the queries used a mixture of upper- and lower-case characters to test the case-insensitive comparison in the code):
speed
ATTACK
Defense
hP
The characteristics of the five input files, and the results of these four queries, are as follows.
speed Grass: 52.5 ATTACK Grass: 55.5 Defense Grass: 56.0 hP Grass: 52.5
speed Fire: 89.0 ATTACK Fire: 86.8 Defense Grass: 79.5 hP Grass: 66.25
speed Psychic: 116.25 ATTACK Fighting: 99.0 Defense Rock: 115.0 hP Fairy: 82.5
speed Ghost: 100.0 ATTACK Fighting: 102.85714285714286 Defense Steel: 190.0 hP Normal: 78.3529411764706
speed Flying: 102.5 ATTACK Dragon: 112.125 Defense Steel: 126.37037037037037 hP Dragon: 83.3125