Answered step by step
Verified Expert Solution
Link Copied!

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 1 OF MY ASSIGNMENT WHICH IS DESCRIBED BELOW:
Step 1: Assignment4.py
In Assignment4.py 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 record_dict.
This class should implement the following methods:
__init__ Constructor that takes the a file_name and file_title as an argument.
The method should create a record_dict attribute and makes a call to the
load_data method.
record_dict: dictionary that will create a key-value pair using file_title 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
load_data Method takes file_name and file_title as arguments, and loads the
data from the file and makes a call to the _create_container 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 record_dict using
file_title 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 file_title and data. Please refer to the structure of record_dict 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().
_create_container Method takes the first line of the file, which contains the
names of the columns, as an argument. It must make a call to
_standardize_col_names 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
_standardize_col_names - Method takes list of column names and replaces
_,- and blank spaces with an empty string, you can use str.replace method
to do this. After standardizing the column names, check that all column names
are alpha-numeric (meaning its only letters and numbers). If the column names
are not alpha-numeric, you must raise a custom exception called
InvalidColumnNames described below in Step 2. 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.
record_stats - Method takes the file_title, 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 file_title dictionary using stats_column_name as the key (this
should also be done dynamically).
extract_top_n - Method takes an integer, file_title and a stats_column_name as
arguments. It must return the top n most frequent values for the Counter object
created by the record_stats method for the given column, where n is the integer
that was passed into the function. If the stats_column_name doesnt exist, you
must raise a custom NoRecordStatsFound exception described below. You
must pass the stats_column_name 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 15 columns)OF credit card csv are as follows
Series_reference ,Period ,Data_value ,Suppressed, STATUS ,UNITS, Magnitude, Subject, Group,Series_title_1,Series_title_2,Series_title_3, Series_title_4, Series_title_5
where ,Series_title_3, Series_title_4, Series_title_5
have no entries
FOR customer_complaints column names (total of 18) are :
Date received ,Product ,Sub-product, Issue, Sub-issue ,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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions