#!/usr/bin/env python # coding: utf-8 # # Problem 1 # Import NumPy under the alias `np`. # In[1]: import numpy as np # # Problem 2 # Import pandas under the alias `pd`. # In[2]: import pandas as pd # # Problem 3 # Given the pandas Series `my_series`, generate a NumPy array that contains only the unique values from `my_series`. Assign this new array to a variable called `my_array`. Print `my_array` to ensure that the operation has been executed successfully. # In[3]: my_series = pd.Series([1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9]) my_series # In[4]: #Solution goes here my_array = my_series.unique() my_array # # Problem 4 # Given the pandas DataFrame `my_data_frame`, generate a NumPy array that contains only the unique values from the second column. Assign this new array to a variable called `another_array`. Print `another_array` to ensure the operation has been executed successfully. # In[5]: my_data_frame = pd.DataFrame(np.random.randn(3,5)) my_data_frame # In[6]: #Solution goes here another_array = my_data_frame[0].unique() another_array # # Problem 5 # Count the occurence of every element within the `my_series` variable that was created earlier in these practice problems. # In[7]: my_series.value_counts() # # Problem 6 # Given the function `triple_digit`, apply this to every element within `my_series`. # In[8]: def triple_digit(x): return x + x*10 + x*100 # In[9]: #Solution goes here my_series.apply(triple_digit) # # Problem 7 # Sort the `my_data_frame` variable that we created earlier based on the contents of its second column. # In[10]: my_data_frame.sort_values(0)