Assignment#2
Assignment #2: NumPy and Pandas
CAC 350
Please complete the following questions. A pdf of your Jupyter Notebook is preferred unless that currently is not working for you.
1. Create a 5x7 NumPy array filled with random numbers. Use fancy indexing to access the following entries (row, col): (1,3),(4,5),(3,2), and (0,6).
2. Explain what np.newaxis does and provide an example of how one might use it.
3. What sorting method does np.sort use and what is its runtime complexity (Big-O)? What does this mean?
4. Given the following NumPy array: [4,1,5,2,7,3], what are the indices of the sorted order?
5. Using the array from #1, sort the columns.
6. Using the array from #1, sort the rows.
7. How is a structured array different from a traditional NumPy array, and why might one use it?
8. Complete the following exercise – activity created by Guilherme Samora.
a. Import two datasets: cars1 and cars2.
b. Print the top five rows of each.
c. Clean cars1 removing any unnamed columns (hing: loc might be helpful)
d. How many observations exist in each dataset?
e. Join cars1 and cars2 into one dataframe.
f. Let’s add a column called owners consisting of random numbers from 15,000 to 73,000.
g. Add it to the cars dataframe.
h. Print the last five rows of the dataset.
i. Which car has the min mpg?
j. Which car has the max horsepower?
- 23 July 2022, 10:30 PM
- 23 July 2022, 10:30 PM
- 23 July 2022, 10:30 PM