Page 81 - Informatics_Practices_Fliipbook_Class12
P. 81

4.  Which of the following methods can be used to set the column 'RollNumber' as the index of a DataFrame named
                  'df'?
                  a.  df.set_index('RollNumber')
                  b.  df.index('RollNumber')
                  c.  df.set_index(['RollNumber'])
                  d.  df.index = 'RollNumber'
               5.  Which of the following method is used for label-based indexing in Pandas DataFrame to access specific rows and columns?
                  a.  df.loc[]             b. df.iloc[]           c. df.idx[]           d. df.get()
               6.  Which of the following is the correct way to access the value in the second row and third column of a DataFrame using
                  integer-based indexing?
                  a.  df.get(2, 3)         b. df.loc[1, 2]        c. df.iloc[1, 2]      d. df.slice(1, 2, 2, 3)
               7.  Which of the following statement will correctly create a new DataFrame df2 containing only rows where column A is True
                  in df?
                  a.  df2 = df[df['A'] == True]
                  b.  df2 = df[df['A']]
                  c.  df2 = df[df['A'].bool()]
                  d.  df2 = df[df['A'].isin([True])]
               8.  Consider the following Pandas Series representing color names:
                  s = pd.Series(['Red', 'Green', 'Blue'])
                  Which of the following statements can be used create a DataFrame with two columns: Color containing the color names
                  and Code containing the corresponding color codes ['R', 'G', 'B']?

                  a.  df = pd.DataFrame({'Color': s, 'Code': ['R', 'G', 'B']})
                  b.  df = pd.DataFrame(s, columns=['Color'])
                  c.  df = pd.DataFrame({'Color': s, 'Code': s.str[0]})
                  d.  df = pd.DataFrame.from_dict({'Color': s, 'Code': ['R', 'G', 'B']})
               9.  Which of the following statements can be used to set the column names of a DataFrame df to ['Name',  'Age',
                  'City']?
                  a.  df.columns = ['Name', 'Age', 'City']
                  b.  df.set_columns(['Name', 'Age', 'City'])
                  c.  df.rename_columns(['Name', 'Age', 'City'])
                  d.  df.rename(columns={'Name': 'Name', 'Age': 'Age', 'City': 'City'})
              10.  How can you create a new DataFrame df containing only rows where the Revenue is greater than 5000 in df?
                  a.  df2 = df[df['Revenue'] > 5000]
                  b.  df2 = df[df['Revenue']]
                  c.  df2 = df[df['Revenue'].bool()]
                  d.  df2 = df[df['Revenue'].isin([5000])]
            B.  State whether the following statements are True or False:
               1.  Given a DataFrame named 'df', The slice df.loc[2:5] will yields rows from index 2 to 5 (inclusive).   _________
               2.  To slice rows and columns in a DataFrame using positional integer-based indexing, we can use the
                  loc attribute.                                                                           _________
               3.  The index attribute of the DataFrame can be used to set column labels in a DataFrame.   _________
               4.  The default row and column indexes also known as row and column labels begin with 0.    _________
               5.  The keyword usecols of pd.read_csv is used to specify the list of irrelevant columns.   _________
               6.  Boolean indexing is used to filter a DataFrame based on a boolean condition.            _________
               7.  The keyword argument inplace should be set to False if we want the methods associated with the
                  DataFrame to modify the original dataframe directly.                                     _________

                                                                             Data Handling using Pandas DataFrame  67
   76   77   78   79   80   81   82   83   84   85   86