Q.Consider the DataFrame Scholarship shown below : (3 + 1 + 1 = 5) 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 Answer the following questions : I. Write Python code to create and display the given DataFrame using the Dictionary of Series method. II. Rename row indexes to ['a', 'b', 'c', 'd', 'e'] III. Write Python statement to remove the last row of the given DataFrame
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Creating a DataFrame from a dictionary of Series, renaming row indexes with the index attribute, and removing the last row using drop() or slicing.
Creating the DataFrame from a Dictionary of Series
When you build a DataFrame in pandas, you have several construction methods at your disposal. The dictionary-of-Series approach treats each column as a separate Series object, then bundles them together under column names. Each Series holds the values for one column, and pandas aligns them by their indexes to form rows.
For the Scholarship DataFrame, you need three columns: Name, Course, and Amount. Each becomes a Series. The beauty of this method is that it makes the structure explicit—you see exactly what data belongs to which column, and pandas handles the row alignment automatically.
Here's the code:
import pandas as pd
# Create Series for each column
name_series = pd.Series(['Ananya', 'Karan', 'Simran', 'Rahul', 'Priya'])
course_series = pd.Series(['B.Sc.', 'B.Tech', 'MCA', 'BCA', 'BA'])
amount_series = pd.Series([62000, 67000, 64000, 70000, 69000])
# Build DataFrame from dictionary of Series
scholarship = pd.DataFrame({
'Name': name_series,
'Course': course_series,
'Amount': amount_series
})
print(scholarship)
The dictionary keys become column headers, and the Series values populate the rows. By default, pandas assigns integer indexes starting from 0, which matches the original DataFrame shown in the question.
You could also pass the data directly as lists inside the dictionary without explicitly creating Series objects first—pandas converts them automatically. The Series method is simply more explicit about what you're doing.
Renaming Row Indexes
Row indexes in a DataFrame are stored in the index attribute. When you want to replace the default numeric indexes with custom labels, you assign a new list to this attribute. The list must have exactly as many elements as there are rows, otherwise pandas will raise an error.
For this DataFrame with five rows, renaming to ['a', 'b', 'c', 'd', 'e'] is straightforward:
scholarship.index = ['a', 'b', 'c', 'd', 'e']
print(scholarship)
After this operation, the DataFrame will display with alphabetic row labels instead of 0, 1, 2, 3, 4. The data itself remains unchanged—only the way you reference rows has shifted. You can now select row 'a' instead of row 0. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.