程序代写代做代考 game COMP132, Assignment 4

COMP132, Assignment 4
Due Friday, 18 September, 5pm
Please note that we only accept .ipynb files for your assignment. If you are not using Jupyter Notebook for coding, you must test your code in Jupyter Notebook to make sure it is working properly, and then save it as .ipynb file for submission. Please submit only ONE file to include answers for all questions.
Question 1: Data Types (15 pts) Use the following data to finish this question:
(a) Explain the similarity and di↵erence between Tuple and List. [3 pts] (b) Create a Tuple and a List that contains the country names. [3 pts]
(c) Create a DataFrame for the above data by di↵erent ways. Your dataframe should have 3 columns, named ‘Country’, ‘Capital’ and ‘Currency’.
• Create a DataFrame for the above data from Series. [3 pts]
• Create a DataFrame for the above data from Dictionary. [3 pts]
• Create a DataFrame for the above data from NumPy arrays. [3 pts]
1

COMP132 Assignment #4
Question 2: Pandas DataFrame (70 pts)
Before starting to do any questions, make sure you have imported the Pandas package:
For the following questions, you will be working with the pokemon.csv dataset to implement simple data analysis using Pandas library. Pok ́emon is a series of video games that involves catching and training fictional creatures and using them to battle other Pok ́emon players.
The provided dataset pokemon.csv contains 721 unique Pok ́emon, including their name, first and second type, and basic stats of their skilsl: Hit Points(HP), Attack, Defense, Special Attack (SpAtk), Special Defense (SpDef), and Speed. Detailed explanations of the dataset are given in the following table:
For the purpose of this assignment, we will consider Pok ́emon and their evolutions as various Pok ́emon (evolution is the process of a Pok ́emon changing to a newer upgraded Pok ́emon), which means each row in the dataset is the information of a di↵erent Pok ́emon.
import pandas as pd
Columns
Explanations
Name
Name of each Pok ́emon.
Type 1
Main type. Determines weakness/resistance to attacks.
Type 2
Dual type. Not all Pok ́emon have a dual type.
HP
Hit points, or health, defines how much damage a Pok ́emon can withstand before fainting.
Attack
The base modifier for normal attacks (e.g. scratch, punch).
Defense
The base damage resistance against normal attacks.
SpAtk
Special attack. The base modifier for special attacks (e.g. fire blast, bubble beam).
SpDef
Special defense. The base damage resistance against special attacks.
Speed
Determines which Pok ́emon attacks first in each round.
Generation
Generation (1-6) of each Pok ́emon.
2.1 Understanding DataFrame [4 pts]
Save the data file into your working directory. Load the data into a dataframe. Write single command for each question:
(a) Print the number of rows and columns of the dataframe in a tuple. [1 pt] (b) Show the data type of each column. [1 pt]
(c) Show all the column names of the dataframe. [1 pt]
Page 2 of 5

COMP132 Assignment #4
(d) Print the first 10 rows of the dataframe. [1 pt]
2.2 Data Cleaning [6 pts]
(a) Change the columns header ‘Type 1’ to ‘MainType’ and ‘Type 2’ to ‘DualType’. [2
pts]
(b) Delete the columns ‘ID’ and ‘Legendary’. Show the dataset column names. [2 pts]
(c) Add a new column named ‘Total’, which is the sum of all skill statistics (from ‘HP’ to ‘Speed‘) of a Pok ́emon. [2 pts]
2.3 Subsetting DataFrame [18 pts]
For the following questions, we count from zero, and the numbers given below are the indexes.
(a) Show the 200-210th Pok ́emon name. (Include 200th and 210th) [3 pts]
(b) Find out all 4th generation Pok ́emon. [3 pts]
(c) Show the name, main type and dual type of 150-155th Pok ́emon in a single command. (Include 150th and 155th) [3 pts]
(d) From the 3rd generation Pok ́emon, subset those with Water as main type. [3 pts]
(e) Extract the name and generation from the subset you get in (d). [3 pts]
(f) From the subset you get in (d), find out Flying Pok ́emon (DualType is Flying). Display their names only. [3 pts]
2.4 Data Analysis [42 pts]
(a) Print the total number of 1st generation Pok ́emon. [4 pts]
(b) Find out the top 10 strongest Pok ́emon based on the value of ‘Total’ you get in 2.2(c). [4 pts]
(c) For the Pok ́emon whose speed are greater than 80, find out the top 5 normal attacks. [4 pts]
(d) Find out all the 5th generation Pok ́emon without a dual type. [4 pts]
(e) Calculate the average HP of all Grass Pok ́emon. (Both main type and dual type). [4 pts]
(f) Find out how many Pok ́emon is better at attacking than defensing (normal attack and defense). [4 pts]
Page 3 of 5

COMP132 Assignment #4
(g) Find out the Pok ́emon with the highest special attack skill in Grass and the one in Water (only consider main type). Print which of them has a higher special defense value. [4 pts]
(h) Find out how many Normal type Pok ́emon (Both main type and dual type) have a HP higher than its group average HP. [4 pts]
(i) Write a function that simulates a very simple battle between two Pok ́emon. We only consider the normal attack, defense and speed as their skills, and ignore the type and other statistics. Your function should be given two Pok ́emon’s name as parameters, firstly find out their normal attack, defense and speed values in the dataset, then compare these values to get the winner. The winner is the Pok ́emon having two or more of the skill values higher than the other.
Call your function three times to test. Don’t be serious with the battle result if you found that it is di↵erent from the real game! [10 pts]
Question 3: Data Visualisation (15 pts)
(a) Draw a plot to compare the normal attack and defense skills of Fire and Steel Pok ́emon. Firstly subset all Fire and Steel Pok ́emon (both main type and dual type) to di↵erent datasets. Draw a scatter plot where x axis is the attack value and y axis is the defense value. Observe the plot and use common language to describe the plot. What conclusions do you draw? [10 pts]
(b) Draw a bar chart to show the distribution of various Pok ́emon types where the x axis shows the types and y axis is the number of Pok ́emon of the corresponding type (only consider main type). Axes should be labeled properly and the figure should have a title. [5 pts]
Page 4 of 5