{"cells":[{"cell_type":"markdown","metadata":{"id":"hw2-00"},"source":["# Homework 2: Cleaning Data Using Pandas\n","\n","Welcome! This notebook will guide you from reading the question to submitting\n","your answer. You do not need to finish everything at once. Work from the top of\n","the notebook to the bottom, and run each code cell in order.\n","\n","## Deadline\n","\n","Thu, Oct 15, 2026 (11:00 UTC)\n","\n","## Recommended workflow\n","\n","1. Read the question and the expected input/output carefully.\n","2. Run the cells in **1. Preparation**.\n","3. Complete only the `homework()` function in **2. Your Answer**.\n","4. Run the cases in **3. Test Your Answer** and compare the results.\n","5. Copy the complete `homework()` function and submit it in Omnicampus.\n","\n","If you change your function, run its cell again before running the later cells.\n"],"id":"hw2-00"},{"cell_type":"markdown","metadata":{"id":"hw2-01"},"source":["## Question\n","\n","Using the MyAnimeList dataset [1], compute the mean `Score` for each `Type`, and return the results sorted in descending order.\n","\n"," \n","\n","**Inputs / Outputs:** \n","\n","```python\n","homework(anime_data_extracted: pd.DataFrame) -> pd.Series\n","```\n","\n","| Argument | Type | Description |\n","|---|---|---|\n","| `anime_data_extracted` | `pd.DataFrame` | Preprocessed anime dataset (see Section 1) |\n","\n","| Return | Type | Description |\n","|---|---|---|\n","| result | `pd.Series` | Mean `Score` for each `Type`, sorted in descending order |\n","\n","**Example:** \n","\n","```python\n","result = homework(anime_data_extracted)\n","print(result)\n","```\n","```\n","Type\n","TV 6.8XXXXX\n","Special 6.5XXXXX\n","Movie 6.4XXXXX\n","OVA 6.3XXXXX\n","ONA 6.1XXXXX\n","Music 5.8XXXXX\n","Name: Score, dtype: float64\n","```\n","\n","**Submission Guidelines:** \n","1. Submit the the entire `homework()` function by selecting this week's assignment in the Omnicampus homework section, pasting the function into the submission area, and then clicking [Submit Python Code].\n","\n","**Note:** \n","- Erase the `# Write your answer here` when submitting\n","- The return value of the function should be type `pd.Series`, sorted in descending order by the mean values\n","- Write your answer as one function\n","- You may use any Generate AI (NotebookLM recommended)"],"id":"hw2-01"},{"cell_type":"markdown","metadata":{"id":"hw2-02"},"source":["## 1. Preparation\n","\n","### Import libraries\n","\n","Run the next cell to import the libraries used by this notebook. Do not copy\n","these imports into `homework()`.\n","\n","### Download and prepare the dataset\n","\n","Then run the dataset cell. It downloads the MyAnimeList data, removes rows with\n","an unknown `Score`, and converts `Score` to a numeric column. Do not include\n","this download or loading code inside `homework()`.\n"],"id":"hw2-02"},{"cell_type":"code","execution_count":1,"metadata":{"id":"hw2-03","executionInfo":{"status":"ok","timestamp":1790406802833,"user_tz":-540,"elapsed":603,"user":{"displayName":"木村進太郎","userId":"02485141327510571181"}}},"outputs":[],"source":["import numpy as np\n","import pandas as pd\n","from pandas import DataFrame\n","\n","# Libraries for retrieving data from the web and handling zip files\n","import requests, zipfile\n","from io import StringIO\n","import io\n"],"id":"hw2-03"},{"cell_type":"code","execution_count":2,"metadata":{"id":"hw2-04","executionInfo":{"status":"ok","timestamp":1790407288049,"user_tz":-540,"elapsed":1343,"user":{"displayName":"木村進太郎","userId":"02485141327510571181"}}},"outputs":[],"source":["# Specify the url with data\n","url = 'https://github.com/Hernan4444/MyAnimeList-Database/archive/refs/heads/master.zip'\n","\n","# Acquire data from the url\n","r = requests.get(url, stream=True)\n","\n","# read and extract the zipfile\n","z = zipfile.ZipFile(io.BytesIO(r.content))\n","z.extractall()\n","\n","# Load and clean the data\n","anime_data = pd.read_csv('MyAnimeList-Database-master/data/anime.csv')\n","anime_data_extracted = anime_data[anime_data['Score'] != 'Unknown'].copy()\n","anime_data_extracted['Score'] = pd.to_numeric(anime_data_extracted['Score'])"],"id":"hw2-04"},{"cell_type":"markdown","metadata":{"id":"hw2-05"},"source":["## 2. Your Answer\n","\n","Complete the `homework()` function below.\n","\n","- Keep the function name and parameters unchanged.\n","- Write your code at `# Write your answer here`.\n","- Do **not** put `import` statements, file downloads, or data-loading code\n"," inside the function.\n","- Make sure the function returns the requested result.\n","\n","The temporary value `None` only keeps the starter cell runnable. Replace it\n","with your own code before testing and submitting.\n"],"id":"hw2-05"},{"cell_type":"code","execution_count":3,"metadata":{"id":"hw2-06","executionInfo":{"status":"ok","timestamp":1790407293916,"user_tz":-540,"elapsed":26,"user":{"displayName":"木村進太郎","userId":"02485141327510571181"}}},"outputs":[],"source":["def homework(anime_data_extracted):\n"," # Write your answer here\n"," result = None\n"," return result\n"],"id":"hw2-06"},{"cell_type":"markdown","metadata":{"id":"hw2-07"},"source":["## 3. Test Your Answer\n","\n","Run each test case after completing `homework()`. Trying more than one input\n","makes it easier to find mistakes and increases confidence in your answer.\n","\n","> **Important:** Matching all examples below does **not** guarantee a correct\n","> answer or a full score. Omnicampus uses additional grading cases that are not\n","> shown in this notebook.\n"],"id":"hw2-07"},{"cell_type":"markdown","metadata":{"id":"hw2-08"},"source":["### Test Case 1: Full prepared dataset\n"],"id":"hw2-08"},{"cell_type":"code","execution_count":4,"metadata":{"id":"hw2-09","colab":{"base_uri":"https://localhost:8080/","height":303},"executionInfo":{"status":"ok","timestamp":1790407295511,"user_tz":-540,"elapsed":56,"user":{"displayName":"木村進太郎","userId":"02485141327510571181"}},"outputId":"6c84633c-ba17-460e-b094-d539a14fec81"},"outputs":[{"output_type":"display_data","data":{"text/plain":["Type\n","TV 6.894178\n","Special 6.500507\n","Movie 6.497635\n","OVA 6.321410\n","ONA 6.132749\n","Music 5.882616\n","Name: Score, dtype: float64"],"text/html":["
\n","\n","
\n"," \n","
\n","
\n","
Score
\n","
\n","
\n","
Type
\n","
\n","
\n"," \n"," \n","
\n","
TV
\n","
6.894178
\n","
\n","
\n","
Special
\n","
6.500507
\n","
\n","
\n","
Movie
\n","
6.497635
\n","
\n","
\n","
OVA
\n","
6.321410
\n","
\n","
\n","
ONA
\n","
6.132749
\n","
\n","
\n","
Music
\n","
5.882616
\n","
\n"," \n","
\n","
"]},"metadata":{}}],"source":["# Run this cell after completing homework().\n","your_answer = homework(anime_data_extracted)\n","display(your_answer)\n"],"id":"hw2-09"},{"cell_type":"markdown","metadata":{"id":"hw2-10"},"source":["For this dataset, your answer is correct if it is a\n","`pd.Series` whose index contains the anime `Type` values, whose values are the\n","mean `Score` for each type, and whose values are sorted from highest to lowest.\n","\n","This checks the visible dataset only. Omnicampus also checks the output type\n","and values with its grading data.\n"],"id":"hw2-10"},{"cell_type":"markdown","metadata":{"id":"hw2-11"},"source":["### Test Case 2: Small dataset with hand-checkable means\n"],"id":"hw2-11"},{"cell_type":"code","execution_count":5,"metadata":{"id":"hw2-12","colab":{"base_uri":"https://localhost:8080/","height":209},"executionInfo":{"status":"ok","timestamp":1790407297786,"user_tz":-540,"elapsed":10,"user":{"displayName":"木村進太郎","userId":"02485141327510571181"}},"outputId":"22504f71-b9c8-49ba-9982-158b5e6ccf17"},"outputs":[{"output_type":"display_data","data":{"text/plain":["Type\n","Movie 8.0\n","TV 7.0\n","OVA 5.0\n","Name: Score, dtype: float64"],"text/html":["
\n","\n","
\n"," \n","
\n","
\n","
Score
\n","
\n","
\n","
Type
\n","
\n","
\n"," \n"," \n","
\n","
Movie
\n","
8.0
\n","
\n","
\n","
TV
\n","
7.0
\n","
\n","
\n","
OVA
\n","
5.0
\n","
\n"," \n","
\n","
"]},"metadata":{}}],"source":["case_2_data = pd.DataFrame({\n"," \"Type\": [\"TV\", \"TV\", \"Movie\", \"Movie\", \"OVA\"],\n"," \"Score\": [8.0, 6.0, 9.0, 7.0, 5.0],\n","})\n","case_2_answer = homework(case_2_data)\n","display(case_2_answer)\n"],"id":"hw2-12"},{"cell_type":"markdown","metadata":{"id":"hw2-13"},"source":["The expected values, in descending order, are:\n","\n","```text\n","Type\n","Movie 8.0\n","TV 7.0\n","OVA 5.0\n","Name: Score, dtype: float64\n","```\n"],"id":"hw2-13"},{"cell_type":"markdown","metadata":{"id":"hw2-14"},"source":["### Final checklist\n","\n","Before moving to Section 4, check the following:\n","\n","- You kept the function name and parameters unchanged.\n","- Your function returns the requested result.\n","- There are no `import` statements inside `homework()`.\n","- There is no file download or data-loading code inside `homework()`.\n","- You ran the `homework()` cell again after your latest edit.\n","- You compared the output of every test case with its expected result.\n"],"id":"hw2-14"},{"cell_type":"markdown","metadata":{"id":"hw2-15"},"source":["## 4. How to Submit Your Answer to Omnicampus\n"],"id":"hw2-15"},{"cell_type":"markdown","metadata":{"id":"hw2-16"},"source":["### Step 1: Copy the complete `homework()` function\n","\n","Copy from the line beginning with `def homework(...):` through\n","the final `return` line. Copy the **function itself**, not only its body.\n","\n","Do not copy import cells, data-download cells, the test-case cells that call\n","`homework()`, the final checklist, or any printed output.\n"],"id":"hw2-16"},{"cell_type":"markdown","source":[""],"metadata":{"id":"0ZIpyW4yrL7_"},"id":"0ZIpyW4yrL7_"},{"cell_type":"markdown","metadata":{"id":"hw2-17"},"source":["### Step 2: Paste it into Omnicampus and submit\n","\n","Open this homework in Omnicampus, paste the complete function\n","into the answer field, and click the submit button.\n","\n","> **🔁 You can submit as many times as you need.**\n",">\n","> If your result is `0.0`, revise your `homework()` function and submit it\n","> again. You do not have to stop after your first submission.\n","\n","The submitted function must not contain library imports. The required\n","libraries are provided by the grader.\n"],"id":"hw2-17"},{"cell_type":"markdown","metadata":{"id":"hw2-18"},"source":["### Step 3: Wait for and check the grading result\n","\n","Grading may take a little time. If no result appears, wait a\n","moment and reload the browser.\n","\n","- **3.0 points** means the answer is correct.\n"," - If you submit after the deadline, **2.0 points** is the maximum you can get.\n","- **0.0 points** means the answer is not correct yet.\n","- You may revise your function and submit again.\n"],"id":"hw2-18"},{"cell_type":"markdown","source":[""],"metadata":{"id":"MWh6WJ-ErG22"},"id":"MWh6WJ-ErG22"},{"cell_type":"markdown","metadata":{"id":"hw2-19"},"source":[" ### Important Notes About Grading\n","\n"," 1. **Your latest submission is your final result.**\n"," Your grade is based on the most recent submission, not the highest score.\n"," For example, if you receive `3.0` and then submit another answer that receives\n"," `0.0`, your recorded result will be `0.0`.\n","\n"," 2. **Correct submissions made during the late submission period receive a maximum of 2.0 points.**\n"," Even if your answer is correct, you cannot receive `3.0` points after the\n"," original deadline.\n","\n"," 3. **The late submission window will be open to all students, including students who have already submitted.**\n"," If your latest submission already shows `3.0`, you do not need to submit\n"," again during the late submission period. Submitting again may replace your\n"," current result.\n","\n"," Before you finish, make sure your latest submission shows the score you want\n"," to keep.\n","\n"],"id":"hw2-19"},{"cell_type":"markdown","metadata":{"id":"hw2-20"},"source":["### References\n","\n","[1] Hernan4444. *MyAnimeList Database*. GitHub. https://github.com/Hernan4444/MyAnimeList-Database"],"id":"hw2-20"}],"metadata":{"colab":{"provenance":[],"toc_visible":true},"kernelspec":{"display_name":"3.10.5","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.5"},"homework_edition":"2026Sep"},"nbformat":4,"nbformat_minor":5}