
Concept explainers
STEP 1: Begin work within your Jupyter Notebook by importing the following modules:
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import re
Jupyter Notebooks
Q1. Within your Jupyter Notebook, write the code for a Python function called
def parseWeatherByYear(year) :
This function will parse an html page containing weather for an entire year of data for the city of Toronto.
The html pages containing weather data can be downloaded from: https://www.extremeweatherwatch.com/cities/toronto/year-2023
The file to parse for this lab however can be downloaded here: https://matrix.senecacollege.ca/~danny.abesdris/prg550.232/labs/lab6/torontoWeather.2023.html
The html file itself contains markers as where to begin parsing the data to extract. The 3 pieces of data that must be extracted consist of the high and low temperatures (in degrees Celsius) as well as the amount of precipitation (in cm) for every day so far in the current year (2023).
A series of lines containing where to begin extracting data is listed below:
<td><div class='width-130'><a href='/cities/toronto/day/january-1'>January 1</a></div></td>
<td class='text-right temp40'>5.0</td>
<td class='text-right temp30'>2.7</td>
<td class='text-right rainsnow1'>0.15</td>
</tr>
Notice the marker in the lines above:
/cities/toronto/day/month-n
In the example above, the data to extract would be: 5.0, 2.7, and 0.15. The extraction can be achieved in several ways, but a carefully structured regular expression (using the match.group( ) directive as well as the re.S and re.M flags) is recommended for speed and simplicity. The trick here is to match text up to the point where the data begins (as groups) and then forming another regular expression that matches the data (again as a group).
As always, the website https://regex101.com will be invaluable in helping you to achieve your solution with this.
The data to be extracted must range from january 1, 2023 to the cutoff date for this file of march 16, 2023.
It would be helpful to create a Numpy array of the number of days in each month of the year and then to investigate the Pandas date_range( ) function and the Series.dt.month_name attribute to allow you to programmatically capture the month names.
https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.month_name.html
The html file itself must be opened and the entire contents read into a string.
As the data from the html file is extracted, your function must also write the data into a CSV (comma separated values) file using the initial heading (title) of:
City,dayOfyear,month,dayOfMonth,Year,highTemp,lowTemp,precipitation
You are to write each field separated by commas (,) and followed by the new line.
The first 10 records of the resultant file should be exactly as listed below:
City,dayOfyear,month,dayOfMonth,Year,highTemp,lowTemp,precipitation
Toronto,1,january,1,2023,5.0,2.7,0.15
Toronto,2,january,2,2023,5.6,3.5,0.00
Toronto,3,january,3,2023,4.4,2.8,0.33
Toronto,4,january,4,2023,4.4,2.5,2.11
Toronto,5,january,5,2023,4.8,3.2,0.02
Toronto,6,january,6,2023,5.1,2.9,0.00
Toronto,7,january,7,2023,3.2,-4.1,0.00
Toronto,8,january,8,2023,-1.5,-4.8,0.00
Toronto,9,january,9,2023,2.2,-1.7,0.01
There are exactly 75 records in the html file to extract and therefore 75 records are to be written to the CSV file.
Once the file has been created and all records written, your function must load the CSV file into a Pandas data frame and display ALL records in the data frame using the functions:
pd.read_csv(csvFile) # read csv file into Data Frame
pd.set_option('display.max_rows', None) # set a flag to display all rows in the output
The data frame's shape attribute and describe( ) method must also be invoked and displayed.
The exact output on the command line should be as listed below:
City dayOfyear month dayOfMonth Year highTemp lowTemp precipitation
0 Toronto 1 january 1 2023 5.0 2.7 0.15
1 Toronto 2 january 2 2023 5.6 3.5 0.00
2 Toronto 3 january 3 2023 4.4 2.8 0.33
3 Toronto 4 january 4 2023 4.4 2.5 2.11
4 Toronto 5 january 5 2023 4.8 3.2 0.02
5 Toronto 6 january 6 2023 5.1 2.9 0.00
...TO 75

Step by stepSolved in 4 steps with 3 images

- Question R .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardC++arrow_forwardCreate a module called chemistry that contains the following three functions: elementName(symbol) This function accepts one string parameter. The symbol represents the name of a specific element on the periodic table. The function returns the name of the element (as string) of the specific element. For example, elementName(Na) returns Sodium. elementName(Li) return Lithium. Note: You are NOT allowed to use lists or any data types not yet covered in class. ionicCompound(e1, c1, e2, c2) This function accepts the chemical symbol and charge for two elements. The function should return the ionic compound created with these two elements. The subscripts should be reduced. ionicName(e1, e2) This function accepts the chemical symbols for two elements. Based on these two symbols the function should return an appropriate chemical name. ionicName(Mg, O) returns Magnesium Oxide. Create a Python program that uses the functions defined in your chemistry module to allow a user to create chemical…arrow_forward
- I want a unique one thanks python code plsarrow_forwardPart 3: JavaScript - Program Outline, Startup Function, and Prompt We are going to use a function that we can consider an entry point into our running JavaScript. Below is an outline of the major elements in our JavaScript file. getRandomInt() function: generate a random integer startup() function: entry point function call to startup() function Below is your startup code: function getRandomInt(min, max) {}function startup() {}startup(); >> Add the above code components to your cis111-07.js JavaScript file below your multiline comment. >> Copy the getRandomInt function code from your previous assignment, or from this Stackoverflow article (Links to an external site.). Remember to add a single line comment above the getRandomInt function that documents the source of the code. Before attempting to use the prompt function in your code, you should try out the function in the console. >> Enter the following into the console to test displaying the prompt dialog. prompt();…arrow_forwardPLEASE COMMENT CODE In a python program, create a new file and call it “ tracking”. Write to it four lines each contains information about an order like this: 1-00654-021 Dell charger Toronto-WEST 99-49-ZAD011-76540-022 ASUS battery Milton-EAST 34-56-CBH561-09239-026 HP HD Scarborough-NORTH 12-98-AZC451-12349-029 Mac FD North York-LAWRENCE 34-49-ZWL01Add the file two more lines: 1-34567-055 Lenovo SSD Milton-ON 34-09-MT04 1-90432-091 Lenovo battery Oakville-ON 78-KL98 Define a function that searches for a brand (e.g. Dell, ASUS, etc.). Test the function in your program.arrow_forward
- NO REGEX OR ANYTHING COMPLICATED PLEASE.. USE BASIC APPROACH Create a program in Python that reads data from Breakfast Menu (https://www.w3schools.com/xml/simple.xml) and builds parallel arrays for the menu items, with each array containing the menu item name, description, calories, and price, respectively. After reading the data and building the arrays, display the menu items similar to the following: name - description - calories - priceAt the bottom, display the total number of items on the menu, the average number of calories per item, and the average price per item similar to: 0 items - 0 average calories - $0.00 average price You may either read the page using Internet processing methods, or you may download and save the page and then read the data from the saved file. You must process the data using string functions (no XML libraries). must use separate subroutines/functions/methods to implement each type of processing, and include error handling for missing or invalid…arrow_forwardEvery data structure that we use in computer science has its weaknesses and strengthsHaving a full understanding of each will help make us better programmers!For this experiment, let's work with STL vectors and STL dequesFull requirements descriptions are found in the source code file Part 1Work with inserting elements at the front of a vector and a deque (30%) Part 2Work with inserting elements at the back of a vector and a deque (30%) Part 3Work with inserting elements in the middle, and removing elements from, a vector and a deque (40%) Please make sure to put your code specifically where it is asked for, and no where elseDo not modify any of the code you already see in the template file This C++ source code file is required to complete this problemarrow_forwardNEED HELP DEBUGGING THE FOLLOW JS CODE JS CODE /* JavaScript 7th Edition Chapter 3 Project 03-05 Application to generate a horizontal bar chart Author: Date: Filename: project03-05.js*/ // Array of phone models sold by the companylet phones = ("Photon 6E", "Photon 6X", "Photon 7E", "Photon 7X", "Photon 8P"); // Units sold in the previous quarterlet sales = (10281, 12255, 25718, 21403, 16142); // Variable to calculate total saleslet totalSales = 0; // Use the forEach() method to sum the sales for each phone model and add it to the totalSales variablesales.forEach(addtoTotal); // For loop to generate bar chart of phone salesfor (let i = 1; i <= phones.length; i++) { let barChart = ""; // Variable to store HTML code for table cells used to create bar chart // Calculate the percent of total sales for a particular phone model let barPercent = 100*sales/totalSales; let cellTag; // Variable that will define the class of td…arrow_forward
- Can you implement a module named inventory that will be responsible for managing the players inventory? The module should hold the inventory and implement the following functions: - displayInventory: Displays the current inventory - addToInventory: Adds an item to the inventory. *Use existing code below and don't use HTML* const prompt = require("prompt-sync")(); var adventurersName = ["Captain Thomas King","George","Tim","Sarah","Mike","Edward",];var len = 0;var Inventory = new Array(5).fill(" ");Inventory[len++] = "Food";Inventory[len++] = "Wine";Inventory[len++] = "Horses";Inventory[len++] = "Medicine"; var adventurersKilled = 3;var survivors;var numberOfAdventurers = adventurersName.length; survivors = numberOfAdventurers - adventurersKilled; displayIntroduction();getLeader(); var user_life = 3;var correct_answer = ["1","2","3"];var userIsCorrect;var options = ["\nOption 1 Enter the village hut?","Option 2 Eat the turkey leg?","Option 3 Sit on the stool?","Option 4 Talk with the…arrow_forwardPlease help me with these question. I am having trouble understanding what to do. Please use HTML, CSS, and JavaScript Thank youarrow_forwardplease use python.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





