Q.What will be the output of the following code: import pandas as pd s1 = pd.Series(data=2*(3, 10)) print(s1)
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 creates a Pandas Series from a tuple multiplied by 2, which repeats the tuple's elements, resulting in a Series with four values: 3, 10, 3, 10, indexed from 0 to 3.
When working with Pandas Series, understanding how Python handles basic operations before the Series is even created matters enormously. This question hinges on what happens when you write 2*(3, 10) in Python.
The expression 2*(3, 10) is tuple multiplication. In Python, when you multiply a tuple by an integer, you get repetition — the tuple's contents are repeated that many times. So 2*(3, 10) produces (3, 10, 3, 10). If you had written 3*(3, 10), you would get (3, 10, 3, 10, 3, 10), and so on. This is a fundamental Python behavior, not specific to Pandas at all.
Once that tuple repetition happens, Pandas receives (3, 10, 3, 10) as the data argument. A Series constructor takes this iterable and builds a one-dimensional labeled array. Since no explicit index is provided, Pandas assigns the default integer index starting from zero.
The data parameter in pd.Series() accepts any iterable — lists, tuples, arrays, even dictionaries. Here, the tuple (3, 10, 3, 10) is perfectly valid input. …
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.