Search for question
Question

Numpy, Pandas Numpy is an effective package for matrix computation. Pandas is an excellent package for data manipulation and analysis. You can download the module by using pip -install pandas.

If you are in Visual Studio, you may use PyPI to install the package. To import the packages, use the following statement in your Python scripts: import numpy as np import pandas as pd To install Jupyter Notebook on your laptop, the procedure is as follows: (1) Install a Python interpreter (version 3.x) (2) Open a Window command window and move the current directory to C:\Users\your_name\AppData\Local\Programs\Python\Python37\Scripts where AppData is a hidden directory (you need to turn on viewing option for hidden directories in Window view option) (3) Type "pip install jupyter" (4) After jupyter notebook Jupyter is installed successfully, type NotebookApp.iopub_data_rate_limit=1000000" (5) In the window of Jupyter, click "New” button and “Python3" to open a new Jupyter new notebook For each of the following tasks, you need to present your running results in the format of screenshots. Source code should be provided through copy and paste. Task 1 NumPy Array Creation (1 point) 1.a Create a NumPy array from a list: [[1,2,3],[4,5,6]] and assign this array to A. 1.b Print the shape of A. Task 2 Numpy Reshape (1 point) 1.c Reshape A to (3, 2) and store the result to B. 1.d Print the shape of B Task 3 NumPy Transpose (1 point) 1.e Transpose B to C 1.f Print the shape of 66 Task 4 NumPy Matrix Dot Operator (1 point) Perform a dot operation between the following two matrices, arr1 and arr2: 1 arr1 = [[1, 2], [3,4.]] arr2 = [[5,6], [7,8]] Print out the resulting matrix. Task 5 NumPy Matrix Multiply Operator (1 point) Perform an operation via using a multiply operator between the following two matrices, arr1 and arr2: arr1 = [[1, 2], [3,4.]] arr2 = [[5, 6 ], [7,8]] Print out the resulting matrix. Task 6 NumPy Matrix Concatenation (1 point) Perform a concatenation operation between the following two matrices (arr1 and arr2) along axis=0 and axis=1, respectively: arr1 = [[1, 2], [3,4]] arr2 = [[5,6], [7,8]] Print out the resulting matrices and their shapes, respectively. Task 7 NumPy Element-wise Matrix Operation (1 point) Perform an element-wise multiplication operation between the following matrix arr1 and 3: arr1 = [[1, 2], [3,4]] Print out the resulting matrix. Task 8 Numpy Copy of Matrix (1 point) Perform a copy operation of the following matrix arr1: arr1 = [[1, 2], [3, 4]] Assign the resulting matrix to be arr2. Then, let arr2[0,0] =0 Last, print out the content of arr1 and arr2. 2 Task 9 Numpy View of Matrix (1 point) Perform a view operation of the following matrix arr1: arr1 = [[1, 2], [3, 4]] Assign the resulting matrix to be tr2. Then, let arr2[0,0] =0 Last, print out the content of arr1 and arr2. Task 10 NumPy Save and Load (1 point) Perform a save operation of the following matrix arr1 as a file named 'test.npy': arr1 = [[1, 2], [3, 4]] Then, use np.load to load the file 'test.npy' back to another matrix arr2. Last, print out the content of arr1 and arr2. Task 11 NumPy Matrix Transpose (1 point) Perform a transpose operation of the following matrix arr3: arr3 = [[1, 2, 3], [4, 5, 6]] Print out the resulting matrix. Task 12 NumPy Broadcasting (1 point) Perform an addition operation between the two following matrices, arr3 and arr4: arr3 = [[1, 2, 3], [4, 5, 6]] arr4 = [1, 2, 3] Convert arr3 and arr4 to Numpy arrays first before performing the addition. Print out the resulting matrix. Task 13 Pandas Series (1 point) Create a Pandas series based on an input python list: [a, b, c, d]. Print out the resulting series. Task 14 Pandas Series with a User-defined Index List (1 point) Create a Pandas series based on an input python list [2, 4, 6, 8] and a user-defined index list [a, b, c, d]. Print out the resulting series. Task 15 Pandas Filtering (1 point) Create a Pandas series based on an input python list [2, 4, 6, 8, 10, 12, 14, 16, 18]. 3 Print out the resulting series. Design a filtering operation that removes any element whose value is less than 7 from the series. Print out the resulting series. Task 15 Pandas Series Booleanization (1 point) Create a Pandas series based on an input python list [2, 4, 6, 8, 10, 12, 14, 16, 18]. Print out the resulting series. Design a booleanization operation that changes any element whose value is less than 7 to 'False' and all the other elements to 'True'. Print out the resulting series. Task 15 Missing Data in Panda (1 point) Create a Pandas series based on an input python list [2, 4, 6, 8, np.nan]. Print out the resulting series. Multiply the resulting series with 5. Print out the new resulting series. Task 16 Panda Creation of DataFrame (1 point) Given the following Python dictionary: data = {'state': ['FL', ‘FL’, ‘GA', ‘GA’, ‘GA’], 'year': [2010, 2011, 2008, 2010, 2011], 'pop' [18.8, 19.1, 9.7, 9.7, 9.8]} : Create a Panda DateFrame. Print out the content of this dataframe. Task 17 Descriptive Statistics of Panda DataFrame (1 point) With the dataframe created from Task 16, print out the descriptive statistics of the dataframe. Task 18 Creation of Panda DataFrame from a .csv File (1 point) Given a "tips.csv" file, create a Panda DataFrame. Print out the first three lines of this dataframe. Task 19 Cross Table of Panda DataFrame (1 point) With the dataframe created in Task 18, create a cross table based on the column names of the dataframe: 'day' and 'size'. 4 Print out the content of this cross table, which is also a data frame. Task 20 Normalization of Cross Table (1 point) With the cross table created in Task 19, normalize it such that the sum of each column of the table is unity. Print out the content of this normalized cross table. 5