SOLUTIONS GRADED A+
✔✔Pandas can be used to join two data frames together. - ✔✔True
✔✔Datasets to be joined generally need something in common, like a customer ID. The
relationship doesn't need to be 1 to 1. (eg. Customer ID may occur once in the first
dataset, and many times in the second dataset) - ✔✔True
✔✔Pandas has functionality to work with complicated dates. - ✔✔True
✔✔When importing data from a local drive, the relative path was defined as the path
FROM where your code in your current working directory is, TO where your data is. -
✔✔True
✔✔for pandas to work, data must be formatted as lists before it is imported. - ✔✔False
✔✔pandas allows use of multiple different data types (like objects and numbers) in a
single table. - ✔✔True
✔✔Usually a programmer will use conventional names when importing packages. But it
is not strictly necessary.
Numpy for example can be imported as:
import numpy as humpty_dumpty - ✔✔True
✔✔What is the output of the following code?
import numpy as np
list1 = [5, 5, 5]
list2 = [10, 10, 10]
np_list1 = np.array(list1)
np_list2 = np.array(list2)
np_list1/np_list2 - ✔✔array([0.5, 0.5, 0.5])
✔✔What is the shape of the following numPy array?
np.random.seed(1955)
x = np.random.randn(2, 2, 2, 2)
print(x.shape)
x
# I have not loaded the necessary packages here... but you should. - ✔✔(2, 2, 2, 2)
, ✔✔What would be returned by the following code? Assume that this is the only
code in the workbook, nothing else is loaded or present.
import pandas as pd
today = datetime.datetime.now()
print(now) - ✔✔an error
✔✔Imagine you have a dataframe called 'tickets', with 4 columns: ('name', 'address',
'parking_spot', 'number_of_tickets')
If you wanted to subset out 2 columns, what code would you use (choose all that apply):
(By subsets I mean just show 2 of 4 columns) - ✔✔tickets.loc[:,['name',
'number_of_tickets']]
AND
tickets[['name', 'number_of_tickets']]
✔✔What is the purpose of np.array in the below code?
a = [6.1, 5.8, 5.97, 5.43]
b = [2.5, 3.19, 2.26, 3.17]
np_a = np.array(a)
np_b = np.array(b) - ✔✔Convert the lists 'a' and 'b' to a numPy array
✔✔Imagine we create a pandas series using the below code. What is one simple way to
retrieve the value 0.5 from the series?
import pandas as pd
df = pd.Series([0.75, 0.25, 1.00, 0.50])
index = ['a', 'b', 'c', 'd']
df - ✔✔df['d']
✔✔What is the mean of the column 'A' in this dataframe generated below?
(choose the closest value)
*you may need to import additional packages or fix minor errors to run the code below
import numpy as np
rng = np.random.default_rng(76829384239487)
#create a dataframe using those random values!
df = pd.DataFrame(rng.integers(0, 100, size=(15,4)), columns = list("ABCD")) -
✔✔58.13
✔✔Imagine we have a dictionary like the 1 below.