Page 90 - Informatics_Practices_Fliipbook_Class12
P. 90

5.  Consider the DataFrame studentDF considered in the previous question. Write a code snippet for the following
              queries based on the DataFrame considered in the previous question:
              (i)  Display the first two records of the DataFrame studentDF.
              (ii)  Retrieve the columns 'Name' and 'RollNumber'.
              (iii)  Retrieve details of students with 'Marks' greater than 85.
              (iv)  Retrieve rows where 'Grade' is A.
              (v)  Use the iloc function to select the rows from index 2 to index 4.
              (vi)  Set column ID(earlier RollNumber) as the row indexes.
              (vii)   Set the column labels of the DataFrame  'df' to be ['Name',  'ID',  'Grade',  'MarksScored']
                  and display the modified DataFrame.
           6.  What is the difference between the following attributes with respect to Pandas DataFrame:
              (i)  head and tail
              (ii)  index and columns
           7.  Consider the following DataFrame studentDf:
                    Name  RollNumber Grade  Marks
              0  Hetansh          10     A     99
              1  Supriya          11     B     82
              2    Mehak          12     A     95
              3    Madhu          13     B     80
              4     Rama          14     C     60
           8.  What will be the output produced on execution of the following statements?
              (i)  print(df.groupby('Grade').count())
              (ii)  print(df['Marks'].mean())
              (iii)  print(df['Marks'].std())
              (iv)  print(df['Marks'].max())
              (v)  print(df.iloc[2]['Name'])
              (vi)  print(df.loc[0:2,'Name':'Grade'])
              (vii)  print(df['Grade'].value_counts())
              (viii) print(df['Grade'].unique())
              (ix)  print(df.groupby('Grade')['Marks'].mean())
              (x)  print(pd.concat([studentDf, studentDf], axis=0))
              (xi)  print(df.rename(columns={'Name': 'Full Name', 'Marks': 'Total Marks'}))
           9.  Consider the DataFrame studentDF of the previous question. Write a code snippet for the following queries based on the
              DataFrame considered in the previous question:
              (i)  Retrieve the summary statistics of the DataFrame
              (ii)  Determine the minimum marks.
              (iii)  Determine the average marks.
              (iv)  Retrieve the number of occurrences for each unique value in the 'Grade' column
              (v)  Add a new column ModeratedMarks to the DataFrame to be calculated as Marks+1
              (vi)  Drop the record of student with the 14 as the roll number from the DataFrame
              (vii)  Rename the column 'RollNumber' to 'RNo'
              (viii) Write the contents of the DataFrame df to a CSV file named 'details.csv'?
              (ix)  Group the DataFrame by 'Grade' and calculate the average marks for each group?








          76   Touchpad Informatics Practices-XII
   85   86   87   88   89   90   91   92   93   94   95