Q. Consider the below given two code fragments. Will they produce the same output ? Why/why not?
(i)
fst = [9, 10, 11]
ob1 = pd. Series (data = fst * 2)
print (ob1)
(ii)
fst = pd. Series (data = [9, 10, 11])
ob2 = pd.Series (data = fst * 2)
print (ob2)
Answer :-
No, both codes will produce different results.
This is because, in the part (i) Series object ob1's data contains a Python list (fst)*2 which will repeat the values of the list two times and the data will contain: 9, 10, 11, 9, 10, 11.
In part (ii), Series object ob2's data contains a Series object (fst) *2, which will perform the vectorized operation on the values of fst and then make it as data of ob2, i.e., 18, 20, 22.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )