Skip to content
Question

Q.(a) Write a Python program to create the following DataFrame using a Dictionary of Series: City State 0 Mumbai Maharashtra 1 Dehradun Uttarakhand 2 Bengaluru Karnataka 3 Hyderabad Telangana

(OR)
(b) Write a Python program to create a Pandas Series as shown below from an ndarray containing the numbers 10, 20, 30, 40, 50 with corresponding indices 'A', 'B', 'C', 'D', 'E'. A 10 B 20 C 30 D 40 E 50
CBSECBSE Class XII Board 2025Subjective· 3mImportance★★★★★
🔒 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 →

Part (a): build the DataFrame from a dictionary of two Series (keys City, State); the default 0..3 index aligns them.

Part (b): make a NumPy ndarray of 10..50 and pass it to pd.Series with index=['A','B','C','D','E'].

Part (a)

A DataFrame can be thought of as a collection of Series that share one index; each key of the dictionary becomes a column header and each value (a Series) fills that column. Because neither Series is given an explicit index, both take the default integer index 0,1,2,3, so they align row-for-row.

import pandas as pd

d = {
    'City':  pd.Series(['Mumbai', 'Dehradun', 'Bengaluru', 'Hyderabad']),
    'State': pd.Series(['Maharashtra', 'Uttarakhand', 'Karnataka', 'Telangana'])
}
df = pd.DataFrame(d)
print(df)

Expected output:

        City        State
0     Mumbai  Maharashtra
1   Dehradun  Uttarakhand
2  Bengaluru    Karnataka
3  Hyderabad    Telangana …

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.