CBSE Class 12 Informatics Practices
Question 30 of 44
Solved 2025 Sample Question Paper CBSE Class 12 Informatics Practices (065) — Question 9
Back to all questions 9
Question Sneha is writing a Python program to create a DataFrame using a list of dictionaries. However, her code contains some mistakes. Identify the errors, rewrite the correct code, and underline the corrections made.
import Pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28}
data = [D1, D2, D3)
df = pd.Dataframe(data)
print(df)import Pandas as pd # Error 1
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28} # Error 2
data = [D1, D2, D3) # Error 3
df = pd.Dataframe(data) # Error 4
print(df)Error 1 — The module should be imported as import pandas as pd (lowercase).
Error 2 — In D3, the value has mismatched quotes.
Error 3 — The list data should use square brackets [], not parentheses.
Error 4 — The Dataframe should be DataFrame (capital 'F').
The corrected code is:
import pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha', 'Age': 28}
data = [D1, D2, D3]
df = pd.DataFrame(data)
print(df)