Answered step by step
Verified Expert Solution
Question
1 Approved Answer
GIVE ME THE PYTHON CODE WHICH SOLVES STEP 1 OF MY ASSIGNMENT WHICH IS DESCRIBED BELOW: Step 1 : Assignment 4 . py In Assignment
GIVE ME THE PYTHON CODE WHICH SOLVES STEP OF MY ASSIGNMENT WHICH IS DESCRIBED BELOW:
Step : Assignmentpy
In Assignmentpy implement a class called Records. This class will represent the
entire record dataset youre working with, credit card transactions and consumer
complaints. The class must have the attribute recorddict.
This class should implement the following methods:
init Constructor that takes the a filename and filetitle as an argument.
The method should create a recorddict attribute and makes a call to the
loaddata method.
recorddict: dictionary that will create a keyvalue pair using filetitle as the
key and another defaultdict as the value, and this nested defaultdict will have an empty list as a value by default. You must use a defaultdict and
lambda function for this behavior
loaddata Method takes filename and filetitle as arguments, and loads the
data from the file and makes a call to the createcontainer method described
below. Using the Entry namedtuple container created, use it to create an Entry
namedtuple for each line in the file. Finally append it to the recorddict using
filetitle as the key for the top layer defaultdict and data as the key for the
nested defaultdict. You should end up with a list of namedtuples associated with
the keys filetitle and data. Please refer to the structure of recorddict given
above.
This method must be able to handle a file not found error, and should ask the
user to input a valid file name until they entered a valid file name or quit if the
user enters q The exception handling must also make use of an else clause
to print to the console that the file was loaded successfully.
Note: to extract the first line of the file you can use the method next
createcontainer Method takes the first line of the file, which contains the
names of the columns, as an argument. It must make a call to
standardizecolnames method described below.
You must then unpack the column names to create a namedtuple called Entry
that will have the column names as the names of the attributes. Return the Entry
namedtuple
standardizecolnames Method takes list of column names and replaces
and blank spaces with an empty string, you can use strreplace method
to do this. After standardizing the column names, check that all column names
are alphanumeric meaning its only letters and numbers If the column names
are not alphanumeric, you must raise a custom exception called
InvalidColumnNames described below in Step You must pass the column
names to the exception and your except statement should print the msg
attribute of the InvalidColumnNames exception class and ask the user to input
the names of the columns by hand. Return the standardized columns list.
recordstats Method takes the filetitle, a column name you wish to process
and a lambda function, as arguments. You will need to retrieve the values for the
given column in the appropriate data list using the lambda function that was
passed in and the map method. Once you have extracted the values use a
Counter object to summarize the number of instances in that column, this
should give you a Counter object that pairs the value in the column with the
number of times that value appeared in your data. Store the result inside of the
appropriate filetitle dictionary using statscolumnname as the key this
should also be done dynamically
extracttopn Method takes an integer, filetitle and a statscolumnname as
arguments. It must return the top n most frequent values for the Counter object
created by the recordstats method for the given column, where n is the integer
that was passed into the function. If the statscolumnname doesnt exist, you
must raise a custom NoRecordStatsFound exception described below. You
must pass the statscolumnname to the exception and your except
statement should print the msg attribute of the NoRecordStatsFound exception
class and have a return statement to exit the method
SO THERE ARE TWO CSVS INVOLVED
COLUMNS total of columnsOF credit card csv are as follows
Seriesreference Period Datavalue Suppressed, STATUS UNITS, Magnitude, Subject, Group,SeriestitleSeriestitleSeriestitle Seriestitle Seriestitle
where Seriestitle Seriestitle Seriestitle
have no entries
FOR customercomplaints column names total of are :
Date received Product Subproduct, Issue, Subissue Consumer complaint narrative, Company public response Company State ZIP code, Tags Consumer consent provided?, Submitted via, Date sent to company Company response to consumer Timely response?, Consumer disputed?, Complaint ID
please make a note that all the rows columns must not contain entries there may be or there might not be
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started