Comprehension

Consider the DataFrame Scholarship shown below:

NameCourseAmount
0AnanyaB.Sc.62000
1KaranB.Tech67000
2SimranMCA64000
3RahulBCA70000
4PriyaBA69000

Answer the following questions:

Question: 1

Write Python code to create and display the given DataFrame using the Dictionary of Series method.

Show Hint

Make one pd.Series for each column, put them in a dictionary with the column names as keys and pass it to pd.DataFrame().
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the method:
In the dictionary of Series method, each column is a Series. The dictionary keys become the column names.
pd.DataFrame(dictionary) then joins the Series side by side. The Series index (0 to 4) becomes the row index.

Step 2: Create one Series per column:
The table has three columns: Name, Course and Amount. Name and Course hold text. Amount holds numbers.
import pandas as pd
name = pd.Series(['Ananya', 'Karan', 'Simran', 'Rahul', 'Priya'])
course = pd.Series(['B.Sc.', 'B.Tech', 'MCA', 'BCA', 'BA'])
amount = pd.Series([62000, 67000, 64000, 70000, 69000])


Step 3: Build the DataFrame and display it:
We put the three Series into a dictionary whose keys are the column names. Then we print the result.
Scholarship = pd.DataFrame({'Name': name, 'Course': course, 'Amount': amount})
print(Scholarship)


Step 4: Output of the program:
Running the code gives:
     Name  Course  Amount
0  Ananya   B.Sc.   62000
1   Karan  B.Tech   67000
2  Simran     MCA   64000
3   Rahul     BCA   70000
4   Priya      BA   69000

This is the same as the table given in the question.

Final Answer:
Create three Series, pass them in a dictionary to pd.DataFrame(), name the result Scholarship and use print(Scholarship).
Was this answer helpful?
0
0
Question: 2

Rename row indexes to ['a', 'b', 'c', 'd', 'e']

Show Hint

Assign a list of five labels to the index attribute of the DataFrame, or use rename() with a dictionary.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the task:
The DataFrame Scholarship has the row labels 0 to 4. We must change them to a, b, c, d, e.
Row labels are stored in the attribute index of the DataFrame.

Step 2: Assign a new list to index:
We give the DataFrame a new list of five labels. The list length must be 5, equal to the number of rows.
Scholarship.index = ['a', 'b', 'c', 'd', 'e']


Step 3: Check the result:
Printing the DataFrame now gives:
     Name  Course  Amount
a  Ananya   B.Sc.   62000
b   Karan  B.Tech   67000
c  Simran     MCA   64000
d   Rahul     BCA   70000
e   Priya      BA   69000


Final Answer:
Scholarship.index = ['a', 'b', 'c', 'd', 'e']
Was this answer helpful?
0
0
Question: 3

Write Python statement to remove the last row of the given DataFrame

Show Hint

Use the drop() method with the label of the last row, which Scholarship.index[-1] gives.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the task:
We must delete the last row of the DataFrame Scholarship. The method that removes rows or columns is drop().
For rows, drop() takes the row label. The default axis is 0, which means rows.

Step 2: Find the label of the last row:
The label of the last row is the last item of the index. Scholarship.index[-1] gives it. This works for the labels 0 to 4 and also for the labels a to e.

Step 3: Write the statement:
Scholarship = Scholarship.drop(Scholarship.index[-1])

drop() returns a new DataFrame, so we store it back.
If the labels are still 0 to 4, Scholarship.drop(4) gives the same result. After the labels change to a to e, Scholarship.drop('e') does the same.

Step 4: Check the output:
The row of Priya is removed and four rows are left.
     Name  Course  Amount
a  Ananya   B.Sc.   62000
b   Karan  B.Tech   67000
c  Simran     MCA   64000
d   Rahul     BCA   70000


Final Answer:
Scholarship = Scholarship.drop(Scholarship.index[-1])
Was this answer helpful?
0
0