PART 1 Create a class called 'simple_math' with two functions and two class variables, and a constructer that sets the two variables. One variable called operand that will hold a string or int value,...


PART 1



  • Create a class called 'simple_math' with two functions and two class variables, and a constructer that sets the two variables.

    • One variable called operand that will hold a string or int value, and one variable called operator that will be either '+', '/', or '-'. You should check it is only one of these values, if it is not throw an appropriate error.

    • One function called user_op() that will take in a number, and apply the operation that operator contains to the input and operand. The format should always be operand-operator-user_input, in order to settle order ambiguity

      • Implement the actual operations using augmented operators






PART 2



  • Read in dataset 'titanic' from seaborn,

  • Create a copy of the titanic dataset called test_data

  • Filter test_data such only floating point columns and boolean columns are remaining (any automated way is acceptable, do not just type the column names. A loop or type-based filter is likely your best way) then filter remaining columns such that only fare values less than 70 remain, and only unique ages remain. i.e. no duplicates on age.

  • Finally drop any rows that have null values (on only the three columns)


PART 3



  • Create a child class called 'tester' of parent class 'simple math', tester will have no constructor or class variables.

    • Create a function call applicator which will take in a data frame and an operand, and try to apply inherited function user_op on each column, and write it to a new column called modified_{column_name}

    • If the user_op fails (it should since one column is a boolean column) then print 'unable to parse {column_name}' and continue.

      • There are many ways to do this, I will not be quite as strict on the tools you use here, but try to have a try-except and df.apply() somewhere in there






PART 4



  • Take the unmodified 'fare' column from the test_data dataframe and read it into a numpy ndarray. Cut the array to the first 40 items, and then reshape the array such that it is 2D or a a matrix of 10x4 (10 rows of 4 columns).

  • Write a function called array_processor that takes in a 2D array and an int, validates that it is 2D (has two dimensions) or prints an error, then multiplies the array by the int and prints it. Then print the sum of each column and row, specifying the index and axis in an organized manner.

Mar 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here