Question: Please make sure that the code works and specify the purpose for which you wrote the codes ( PYTHON ) import numpy import pandas class

Please make sure that the code works and specify the purpose for which you wrote the codes (PYTHON)
import numpy
import pandas
class InputError(Exception):
pass
class ForgetfulCounter():
"""
The purpose of the Forgetful Counter class is to enable a server computer in a data transfer and editing station
to track how many requests have been made by other computers within a specified time period.
"""
def __init__(self, memory_time_ms):
"""
Each computer can make a certain number of requests within a specified time period.
Therefore, a ForgetfulCounter object created for each requesting computer
can be initialized with a different memory_time_ms value.
"""
pass
def ping(self, query_time_ms):
"""
Args:
query_time_ms: Specifies the time of the most recent query from the requesting computer. Must be positive.
It should be greater than the previous value.
Returns:
result: Returns the number of queries from the requesting computer within the "memory_time_ms" specified time period,
including the last query made. Should be of type (int).
Example:
computer_1= ForgetfulCounter(1000)
current_count_1= computer_1.ping(200)-> Returns 1, because 1 ping was received within the [-800:200] time range.
current_count_1= computer_1.ping(400)-> Returns 2, because 2 pings were received within the [-600:400] time range.
current_count_1= computer_1.ping(500)-> Returns 3, because 2 pings were received within the [-500:500] time range.
current_count_1= computer_1.ping(1000)-> Returns 4, because 3 pings were received within the [0:1000] time range.
current_count_1= computer_1.ping(1500)-> Returns 3, because 2 pings were received within the [500:1500] time range.
"""
return NotImplementedError
def fill_spaces(data: numpy.array, editing_mode: int)-> numpy.array:
""" This function will take a numpy.array of size (m,) where m >0 as input.
It is known that the valid numbers within this array are between 0 and 100.
It will fill all values that do not comply with the specified range;
with the previous valid value if editing_mode is 0,
with the average value of the previous and next valid values if editing_mode is 1,
with the average value of the remaining values if editing_mode is 2.
If all data values are outside the desired range, False will be returned.
Args:
data: numpy.array
Returns:
result: numpy.array or bool (False)
Example:
data: numpy.array([1,2,3,4,5,6,-1,8,9,10,11])
editing_mode: 0
result: numpy.array([1,2,3,4,5,6,6,8,9,10,11])
editing_mode: 1
result: numpy.array([1,2,3,4,5,6,7,8,9,10,11])
editing_mode: 2
result: numpy.array([1,2,3,4,5,6,5.9,8,9,10,11])
"""
return NotImplementedError
def remove_duplicates(df: pandas.DataFrame)-> pandas.DataFrame:
""" This function removes rows of duplicate timestamps in a DataFrame with timestamps in its first column
(column name is not known) and keeps only the row of the most recent/newest timestamp in the DataFrame.
The input DataFrame remains unchanged when this function is executed.
Args:
df: DataFrame (pandas.DataFrame)
Returns:
result: DataFrame (pandas.DataFrame)
Example:
Shown in the visual.
"""
return NotImplementedError
def days_until_end_of_year(input_date: str)-> int:
""" This function returns the number of days left until the end of the year when a date in the format of "YYYY-MM-DD" is received.
The current day is not counted.
Args:
input_date: str
Returns:
result: int
Example:
input_date ="2022-12-29"
result =2
"""
return NotImplementedError
def my_max_pooling(matrix: numpy.array)-> numpy.array:
""" When a square matrix of size (N, N) with N being an even number is received as input,
this function creates a new square matrix of size (N/2, N/2) using the maximum number
in each (2,2) non-overlapping area.
Args:
matrix (numpy.array): Input array of size (N,N). N is a multiple of 4.
Returns:
result: numpy.array
Example:
Shown in the visual.
"""
return NotImplementedError
def find_problematic_boroughs(df: pandas.DataFrame)-> list:
""" This function returns the names of the top 5 boroughs with the highest number of illegal parking complaints
(Illegal Parking / Complaints) and their complaint counts as tuples from the DataFrame
"311-service-requests.csv" read with the file_read function.
Args:
df: Dataframe (pandas.DataFram
Please make sure that the code works and specify

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!