Skip to content
Question

Q.Consider the following Python code : import pandas as pd S1=pd.Series(['Rubina','Jaya','Vaibhav'],index=[10,16,18]) S2=pd.Series(, index=[10,16,18]) S3=pd.Series([56,67,86],) xiia={'Name':,'Subject':S2,'Marks':S3} df=pd.DataFrame() print(df) Complete the above Python code to display the following output : Name Subject Marks 10 Rubina IP 56 16 Jaya HSc 67 18 Vaibhav IP 86

CBSECBSE Class XII Board 2024Subjective· 2mImportance★★★★★
🔒 Locked · start free trial →

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 →

The code builds a DataFrame from three Series, where the missing parts supply the second Series’ data, the third Series’ index, the dictionary key for the Name column, and the dictionary itself as the DataFrame argument.

Let’s walk through what this code is trying to do. You have three Series — S1, S2, and S3 — each with the same index [10, 16, 18]. The first Series, S1, is already given: it holds the names 'Rubina', 'Jaya', and 'Vaibhav'. The output shows that the DataFrame will have three columns: Name, Subject, and Marks. The index of the DataFrame is the same [10, 16, 18], which matches the indices of the Series.

Now look at the output row by row. For index 10, the Name is Rubina, Subject is IP, and Marks is 56. For index 16, Name is Jaya, Subject is HSc, and Marks is 67. For index 18, Name is Vaibhav, Subject is IP, and Marks is 86.

So the missing pieces are:

  1. S2 — the Subject Series. It must contain ['IP', 'HSc', 'IP'] in that order, because that’s what appears in the output for indices 10, 16, and 18 respectively. So the blank in S2=pd.Series(______, index=[10,16,18]) should be filled with ['IP','HSc','IP'].

  2. S3 — the Marks Series. It already has the data [56, 67, 86], but its index is missing. The output shows that the marks align with the same index [10, 16, 18]. So the blank in S3=pd.Series([56,67,86],______) should be index=[10,16,18].

  3. The dictionary xiia — it maps column names to the Series. The key for the Name column is missing. Since S1 holds the names, the blank in 'Name':______ should be S1. The other two keys ('Subject' and 'Marks') are already correctly assigned to S2 and S3.

  4. The DataFrame constructor — pd.DataFrame(______). The dictionary xiia is already built, so this blank should simply be xiia. …

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.