Professional Documents
Culture Documents
Q1. What is a Series and how is it different from a 1-D array, a list and a dictionary?
Ans:
A Series is a one-dimensional array containing a sequence of values of any data type
(int, float, list, string, etc) which by default have numeric data labels starting from zero.
Series vs 1-D array
Series can have default as well as predefined index labels whereas a numpy 1-d array
has only default indexes
Series can contain values of any datatype whereas arrays can contain elements of same
data type
Series vs List
Series can have default as well as predefined index labels whereas a list has only default
indexes
Series vs dictionary
Series elements can be accessed using default indexes as well as its row labels
Whereas dictionary elements cannot be accessed using default indexes. They hv to be
accessed using the predefined keys.
Q3. Differentiate between size attribute and count() in Series with an example.
Ans:
size is an attribute of Series which gives the number of values in the Series.
>>> s=pd.Series([7,9.6,'sush'])
>>> s.size
3
WHEREAS
count() is a function that returns the number of non NaN values from the
series
>>> s=pd.Series([7,8,np.nan,"piyush",90])
>>> s.count()
4
Q4. Create a series Vowels1 having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ having
values [2,5,6,3,8] respectively.
Ans:
Q5. Change the index labels of Vowel1 to ‘A’,’E’,’I’,’O’,’U’.
Q6. Give the name “VOW” to the index of the above created series.
Ans 5 and 6
Q8. Write statement to check whether the series Vowels1 is empty or not.
Ans:
Q9. Write statement to Retrieve and print alternate elements from the given series,
starting from index “E”.
Ans:
Ans:
0 18.0
1 38.0
2 62.0
3 85.0
4 50.0
Q11. Given a Pandas series called Series S having 10 elements, the command which will
display all elements from index number 2 to 7 with step size 2.
Ans: print ( S [ 2 : 8 : 2 ] )
Q12. Given the following Series S1:
Write the command to find the elements which are greater than 40.
Ans: print(s [ s > 40 ] )