Thursday 18 March 2021

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers (Informatics Practices) (#class12IP)(#eduvictors)(#PythonPandas)

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers
(Informatics Practices) 

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers (Informatics Practices) (#class12IP)(#eduvictors)(#PythonPandas)

 

Q1: When a Series is created, are the data values mutable or not?

Answer: Yes data values can be modified and are mutable.


Q2: When a Series is created, can it be resized?

Answer: No. Its size Immutable.


Q3: Consider the following snippet

>>> import numpy as np

>>> import pandas as pd

>>> series1 = pd.Series(np.arange( 10, 20, 1 ))


(a) What will the be output the following statement.

      >>> print(series1.head())


(b) What will be the command to display three data values from the end.


Answer

(a) head() displays top five data items.

Output is:

0   10

1   11

2   12

3   13

4   14

dtype: int32



(b) series.tail(3)  

         or 

     print(series.tail(3))



Q4: What is the purpose of series.tail() method?

Answer: tail() method returns the last n members of the series. If the value for n is not passed, then by default n takes 5 and the last five members are displayed.


Q5: What is the output of the following snippet?

>>> import numpy as np

>>> import pandas as pd

>>> series1 = pd.Series([10, 20, np.nan, 40, 50 ])

>>> print(series1.count())


Answer: Output is 4.

It is not 5 because count() method returns the number of non-NaN values in the Series.


Q6: Consider the following python snippet.

>>> import pandas as pd1

>>> import numpy as np1

>>> data = {'P': 0., 'R': 1., 'E': 2.,'M': 2.}

>>> s=pd1.Series(data,index=['P','c','M','a'])

>>> print(s)


What is the output?


Answer

P    0.0

c    NaN

M   2.0

a    NaN

dtype: float64


Reason: Series can be created using dictionaries. Dictionary keys of become indices in the series. In the above snippet, the label indices tries to match the dictionaries key indices. For mismatch, (e.g. c and a) NaN value is assigned.


Q7: What are the two common ways for accessing the elements of a series?

Answer: Indexing and Slicing


Q8: Name the two by of Indexes supported by Pandas Series.

Answer: Indexes are of two types: positional index and labelled index. Positional index takes an integer value that corresponds to its position in the series starting from 0, whereas labelled index takes any user-defined label as index.


Q9: Consider the following snippet:

>>> import pandas as pd

>>> seriesCapCntry = pd.Series(['NewDelhi', 'Washington DC', 'London', 'Paris'],

                                             index=['India', 'USA', 'UK', 'France'])


What is the output of following statements? What type of indexing is used in each of the following?

(a) >>> seriesCapCntry['India']

(b) >>> seriesCapCntry[1]


Answer:

(a) 'NewDelhi'

     Uses user-defined labelled indexing.

(b) 'Washington DC'

     Uses positional indexing.



Q10: Consider the following snippet:

>>> import pandas as pd

>>> seriesCapCntry = pd.Series(['NewDelhi', 'WashingtonDC', 'London', 'Paris'],

                                             index=['India', 'USA', 'UK', 'France'])


What is the output of following statements? 

(a) >>> seriesCapCntry[1:3]

(b) >>> seriesCapCntry['USA' : 'France']]


Answer:

(a) Output is:

USA   Washington DC

UK     London

dtype: object


Note: It excludes the value at index position 3


(b) Output is:

USA     Washington DC

UK       London

France Paris

dtype: object


Note: While using labelled indexing in slicing, value at the end index label is also included in the output.


Q11: In the above snippet, how to print the data items of seriesCapCntry series in reverse order?

Answer: seriesCapCntry[ : : -1]


Q12: What is the output of the following snippet?

>>> import pandas as pd

>>> s = pd1.Series([1, 2, 3])

>>> t = pd1.Series ([1, 2, 4])

>>> u=s*t 

>>> print (u)


Answer

0     1

1     4

2    12

dtype: int64


Note: Series u is created filled with values of multiplication operation.



Q13(MCQ): Given a Pandas series called Sequences, the command which will display the first 4 rows is __________________.

a. print(Sequences.head(4))

b. print(Sequences.Head(4))

c. print(Sequences.heads(4)

d. print(Sequences.Heads(4))

[CBSE Sample Paper 2020-21]

Answer: (a) print(Sequences.head(4))


Q14(MCQ): Given a Pandas series called S1, the command which will display the last 3 rows is _____.

a. print(S1.tail(3)) 

b. print(S1.Tail(3))

c. print(S1.tails(3)) 

d. print(S1.Tails(3))


Answer:  a. print(S1.tail(3)) 


Q15: (a) Create a series S1 having values and indexes as shown below. 

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers (Informatics Practices) (#class12IP)(#eduvictors)(#PythonPandas)


(b) Write the command to add all elements of Series S1 by 5.


Answer

(a) import pandas as pd

S1 = pd.Series([23,55, 67, 89], index=['W', 'X', 'Y', 'Z'])


(b) print (S1+5)

or 

      S2=S1+5 



Q16: Consider the following Series objects S1 and S2. What is be output is two series are added using command?

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers (Informatics Practices) (#class12IP)(#eduvictors)(#PythonPandas)


(a) S1 + S2

(b) s1.add(s2, fill_value=10)


Answer

CBSE Class 12 - Data Handling Using Pandas-Part -2 - Questions and Answers (Informatics Practices) (#class12IP)(#eduvictors)(#PythonPandas)

Q17: What is the output of the following snippet?

>>> import pandas as pd

>>> s1 = pd.Series('Hello', [1, 2, 3, 4])

>>> print (s1)


Answer: Output is:

1    Hello

2    Hello

3    Hello

4    Hello

dtype: object


Q18: What is the difference between Numpy Array and Series Object?


Answer


  Numpy Array Series Object
Arithmetic
Operations
Both the ndarrays
should be of same shape.
Operation will perform on
matching indexes, Irrespective
of their sizes. Mismatched indexes
are filled with NaN values by default.
Indexes /
Data Labels
Numeric and Unique. Non Numeric,can be duplicate.


👉See Also:

1 comment:

  1. it gave me a lot of confidence.but i thhink it is very simple and please increase the questions as well as the increase the quality of these question

    ReplyDelete

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.