State the output of the following code.
import pandas as pd
series1 = pd.Series(10,[11,22,33])
print(series1)
State the output of the following code.
import pandas as pd
series1 = pd.Series(10,[11,22,33])
print(series1)
Solution
The first argument of pd.Series() is the data and the second is the index. Here the data is the scalar 10 and the index is [11, 22, 33]. When the data is a scalar, pandas repeats it for every index label, so the output is:
11 10
22 10
33 10
dtype: int64
Option 3: the default index 0, 1, 2 is used only when no index is passed. Here [11,22,33] is the index.
Option 4: this would be the output of pd.Series([11,22,33]), where the list is the data, not the index.
Option 2: a ValueError occurs only when the data is a list whose length differs from the index. A scalar is always broadcast to the index length.