Path: blob/main/quiz/quiz2.ipynb
3223 views
Q1
For the following code, which of the following statements will not return True?
Q2
In the above python code, the keys of the dictionary d represent student ranks and the value for each key is a student name. Which of the following can be used to extract rows with student ranks that are lower than or equal to 3?
Q3
Suppose we have a DataFrame named df. We want to change the original DataFrame df in a way that all the column names are cast to upper case. Which of the following expressions is incorrect to perform the same?
Q4
For the given DataFrame df we want to keep only the records with a toefl score greater than 105. Which of the following will not work? 
Q5
Which of the following can be used to create a DataFrame in Pandas? √: Python dict / Pandas Series object / 2D ndarray ×:
Q6
Which of the following is an incorrect way to drop entries from the Pandas DataFrame named df shown below? 
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-38-552270aa5b54> in <module>()
----> 1 df.drop('SOP')
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
4172 level=level,
4173 inplace=inplace,
-> 4174 errors=errors,
4175 )
4176
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
3885 for axis, labels in axes.items():
3886 if labels is not None:
-> 3887 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
3888
3889 if inplace:
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\generic.py in _drop_axis(self, labels, axis, level, errors)
3919 new_axis = axis.drop(labels, level=level, errors=errors)
3920 else:
-> 3921 new_axis = axis.drop(labels, errors=errors)
3922 result = self.reindex(**{axis_name: new_axis})
3923
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexes\base.py in drop(self, labels, errors)
5282 if mask.any():
5283 if errors != "ignore":
-> 5284 raise KeyError(f"{labels[mask]} not found in axis")
5285 indexer = indexer[~mask]
5286 return self.delete(indexer)
KeyError: "['SOP'] not found in axis"
Q7
For the Series s1 and s2 defined below, which of the following statements will give an error?
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2894 try:
-> 2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 1
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
<ipython-input-48-42fe26c38f36> in <module>()
----> 1 s2.loc[1]
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
877
878 maybe_callable = com.apply_if_callable(key, self.obj)
--> 879 return self._getitem_axis(maybe_callable, axis=axis)
880
881 def _is_scalar_access(self, key: Tuple):
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
1108 # fall thru to straight lookup
1109 self._validate_key(key, axis)
-> 1110 return self._get_label(key, axis=axis)
1111
1112 def _get_slice_axis(self, slice_obj: slice, axis: int):
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexing.py in _get_label(self, label, axis)
1057 def _get_label(self, label, axis: int):
1058 # GH#5667 this will fail if the label is not present in the axis.
-> 1059 return self.obj.xs(label, axis=axis)
1060
1061 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\generic.py in xs(self, key, axis, level, drop_level)
3489 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
3490 else:
-> 3491 loc = self.index.get_loc(key)
3492
3493 if isinstance(loc, np.ndarray):
c:\users\syy\appdata\local\programs\python\python36-32\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:
-> 2897 raise KeyError(key) from err
2898
2899 if tolerance is not None:
KeyError: 1
Q8
Which of the following statements is incorrect?
TIP: Keep in mind that iloc and loc are not methods, they are attributes
Q9
For the given DataFrame df shown above, we want to get all records with a toefl score greater than 105 but smaller than 115. Which of the following expressions is incorrect to perform the same? 
Q10
Which of the following is the correct way to extract all information related to the student named Alice from the DataFrame df given below: 